【发布时间】:2019-10-08 07:55:48
【问题描述】:
如何通过模式匹配在纯脚本中实现head 或singleton 函数?问题是编译器需要明确定义最广泛的模式,但我无法为我不知道的类型生成默认值。
fromSingleton :: forall a. a -> Array a -> a
fromSingleton _ [x] = x
fromSingleton def [] = def
返回:
A case expression could not be determined to cover all inputs.
The following additional cases are required to cover all inputs:
_ _
Alternatively, add a Partial constraint to the type of the enclosing value.
但是这个提议看起来很虚,我不能补充:
fromSingleton _ _ = ??? (a -- is any type, how can I implement default for it?)
【问题讨论】:
标签: purescript