【发布时间】:2010-12-06 18:59:55
【问题描述】:
我需要一个像这样工作的函数:
some :: (Int, Maybe Int) -> Int
some a b
| b == Nothing = 0
| otherwise = a + b
用例:
some (2,Just 1)
some (3,Nothing)
map some [(2, Just 1), (3,Nothing)]
但我的代码引发了错误:
The equation(s) for `some' have two arguments,
but its type `(Int, Maybe Int) -> Int' has only one
我不明白。
提前致谢。
【问题讨论】:
-
some = uncurry $ maybe 0 . (+) -
您可能对如何使用
Maybe a类型answered here 的更一般的问题感兴趣。
标签: haskell