我创建了一种数据类型来存储有关一组人的信息:出生日期。数据类型只是两个三元组列表,第一个列表包含名称(first, middle, last)
,第二个列表包含DOB(日,月,年)。你可以看到下面的数据类型(我省略了DOB类型,因为它是不相关的这个问题):无法与实际类型'([Char],[Char],[Char])匹配预期类型'x''
data Names = Names [(String, String, String)]
data People = People Names
我想要编写创建初始列表的功能,因此它返回的名称第一个人,然后列表People
。这是迄今为止:
initiallist :: ([String], People)
initiallist = (first_name, all_people)
where first_name = "Bob" : "Alice" : "George" : []
all_people = People ("Bob","Alice","George") : []
这导致
error:
* Couldn't match expected type `Names'
with actual type `([Char], [Char], [Char])'
* In the first argument of `People', namely `("Bob", "Alice", "George")'
In the first argument of `(:)', namely
`People ("Bob", "Alice", "George")'
In the expression: People ("Bob", "Alice", "George") : []
现在,在我的Haskell的知识,我认为String
只是一个[Char]
。所以我觉得我的代码可以正常工作,但它让我绝对难住。