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。
---
<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 :(得分: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]
但没有粉丝字符串数组
我不确定我明白你要做什么;粉丝列表是您数据类型的一部分,您不能忽略它。