1
我正在尝试使用Haskell 99 Questions来学习Elm。问题7你必须定义一个嵌套的列表结构。我试过这样:(阅读this有些为主)在Elm中定义一个嵌套或递归列表结构
type NestedList a = Node a | List (NestedList a)
myList : NestedList number
myList =
[Node 1]
但是我得到这个以下错误:
The type annotation is saying:
NestedList number
But I am inferring that the definition has this type:
List (NestedList number)
这是没有道理给我。当然List (NestedList number)
是匹配Node a | List (NestedList a)
的第二面?
好的,所以在''NestedList''中定义''''时使用'List',而不是使用内建的名称。作为后续工作,我如何定义一个更复杂的结构,例如[1,2,[3,4,[5]],6]使用这个? –
我已经更新了我的答案,以更充分地捕捉问题#7的精神,并且它包含了复杂的嵌套列表示例。 –
太好了。我认为需要一段时间才能沉浸在...因此,事物的NestedList或者是Node的事物,或者是NestedLists列表的NestedList!感谢您抽出时间 - 非常感谢。 –