【发布时间】:2019-11-12 22:36:33
【问题描述】:
我做了一些研究,但找不到任何东西。我不明白这样的功能是如何工作的:
func :: Maybe (Int) -> Maybe (Int)
我应该如何进行模式匹配?我试过了,但没有用:
func Just a = Just a | otherwise = Nothing
func Nothing = Just Nothing | otherwise = Nothing
我怎样才能做到这一点?
错误信息:
exercises6.hs:83:22: error: parse error on input ‘|’ | 83 | func Just a = Just a | otherwise = Nothing | ^
【问题讨论】:
-
这里有很多错误(别担心,我们都会犯,尤其是第一次学习时)。我很好奇你想用
| otherwise = Nothing在这里实现什么。 -
第二。我对守卫犯了这个确切的错误。你会明白的。
标签: haskell functional-programming maybe