在haskell代码

时间:2016-11-02 15:48:41

标签: haskell

我遇到了以下代码:

data Nested a = a :<: (Nested [a]) | Epsilon

mylength Epsilon    = 0
mylength (_ :<: xs) = 1 + mylength xs

a :<: (Nested [a])是什么意思?我不理解这些代码(特别是:<:

1 个答案:

答案 0 :(得分:4)

:<:是一个数据构造函数,如Just。唯一的区别是它是中缀,因为它是象征性的。中缀数据构造函数必须以:开头。

您可以将上述内容重写为:

data Nested a = Nest a (Nested [a]) | Epsilon

mylength Epsilon    = 0
mylength (Nest _ xs) = 1 + mylength xs