【发布时间】:2017-07-15 23:26:18
【问题描述】:
有没有办法在 PureScript 中对未知长度的数组进行模式匹配?例如,下面是我在 Haskell 中使用 List 的方法:
addFirstTwo :: (Num a) => [a] -> a
addFirstTwo (x:y:_) = x + y
我在 PureScript 中尝试过类似的操作(使用 Array a 而不是 [a]),但出现以下错误:
运算符 Data.Array.(:) 不能在模式中使用,因为它是函数 Data.Array.cons 的别名。 模式中只能使用数据构造函数的别名。
我知道我可以在 PureScript 中使用 Lists 而不是数组,但我想对数组进行模式匹配。看了Array pattern matching section of PureScript by Example之后没看到怎么做。
【问题讨论】:
标签: purescript