2017-03-17 44 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

相关问题