我有过
data Weight = Fin Integer | Inf
deriving (Eq, Ord, Show)
negate :: Weight -> Weight
negate Inf = error "negative infinity not supported"我要negate Fin (-1) = Fin 1。所以我进一步定义
negate Fin x = Fin (0 - x)但这会造成错误
? Equations for ‘negate’ have different numbers of arguments我怎么才能修好它?谢谢!
发布于 2018-06-27 12:38:10
模式匹配需要括号:
negate (Fin x) = Fin (0 - x)否则,看起来你有两个论点。
这反映在错误:“方程的‘否定式’有不同数量的参数”。
这不适用于Inf,因为它不需要参数。
https://stackoverflow.com/questions/51062960
复制相似问题