我創建了一種數據類型來存儲有關一組人的信息:出生日期。數據類型只是兩個三元組列表,第一個列表包含名稱(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]
。所以我覺得我的代碼可以正常工作,但它讓我絕對難住。