【发布时间】:2017-08-26 17:41:16
【问题描述】:
我创建了一种数据类型,用于存储有关一组人的信息:他们的姓名和出生日期。数据类型只是两个三元组列表,第一个列表包含名称(first, middle, last),第二个包含 DOB(日、月、年)。你可以看到下面的数据类型(我省略了 DOB 类型,因为它与这个问题无关):
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]。所以我认为我的代码可以正常工作,但它让我非常难过。
【问题讨论】:
标签: haskell