您好我试图使用叠加条件,但我得到解析错误:
parse error on input ‘|’
isAssignMent::String->Bool
isAssignMent a
| a == "" = False
| otherwise
| (head trimmed) == '=' = True
| otherwise = False
where
trimmed = trimRightSide a [' ', '\n']
我做错了什么?谢谢
答案 0 :(得分:5)
这是你想要的吗?
isAssignMent::String->Bool
isAssignMent a
| a == "" = False
| (head trimmed) == '=' = True
| otherwise = False
where
trimmed = trimRightSide a [' ', '\n']
按顺序检查Guard子句。你最后只需要一个otherwise
条款。
答案 1 :(得分:5)
您还可以使用模式匹配来更加惯用地编写:
isAssignMent::String->Bool
isAssignMent "" = False
isAssignMent a
| '=':_ <- trimmed = True
| otherwise = False
where
trimmed = trimRightSide a [' ', '\n']