2017-03-17 43 views
0
data Film = Film String String Int [String] deriving (Eq, Ord, Show, Read) 
--that's my custom data type, (Film *filmname, director, year of release, fans) 

addFilm :: Film -> [Film] -> [Film] 
addFilm newFilm filmList = filmList ++ [newFilm] 

--this is for adding a new film to the list, but without the fans string array 

該模塊正在加載到WinGHCi沒有錯誤,但我不知道如何代替filmList。作爲filmList參數的值,輸入什麼?

--- 
<interactive>:63:30: 
    Couldn't match type `Char' with `Film' 
    Expected type: [Film] 
     Actual type: [Char] 
    In the second argument of `addFilm', namely `"Jordan Vogt-Roberts"' 
    In the expression: 
     addFilm "Kong: Skull Island" "Jordan Vogt-Roberts" 2017 
    In an equation for `it': 
     it = addFilm "Kong: Skull Island" "Jordan Vogt-Roberts" 2017 
*Main> addFilm "Kong: Skull Island" "Jordan Vogt-Roberts" 2017 filmList 

<interactive>:64:57: Not in scope: `filmList' --- that's what I input. 

回答

0

您需要使用數據構造函數,而不僅僅是參數。如果要創建類型爲Film的值,則需要編寫例如:Film "Kong: Skull Island" "Jordan Vogt-Roberts" 2017 ["Fan One","Fan Two"]

更具體地說,像data TypeName = DataConstructor String這樣的數據聲明創建功能DataConstructor :: String -> TypeName。在你的情況下,這是Film :: String -> String -> Int -> [String] -> Film

例子:

skullIsland = Film "Kong: Skull Island" "Jordan Vogt-Roberts" 2017 ["Fan One","Fan Two"] 
otherMovie = Film "Movie Name" "The Director" 2000 ["Lazersmoke","Saad"] 

addFilm skullIsland [otherMovie,otherMovie] 

,但沒有球迷字符串數組

我不知道我明白你正在嘗試做的;粉絲列表是你數據類型的一部分,你不能忽略它。

+0

我想我的意思是空串的粉絲,而不是「沒有它」。對不起,謝謝。 – Saad

相關問題