Reputation: 2439
Hello I'm trying to use imbricated conditions but I get parse error:
parse error on input ‘|’
isAssignMent::String->Bool
isAssignMent a
| a == "" = False
| otherwise
| (head trimmed) == '=' = True
| otherwise = False
where
trimmed = trimRightSide a [' ', '\n']
What am I doing wrong? Thank you
Upvotes: 1
Views: 344
Reputation: 52029
Is this what you want?
isAssignMent::String->Bool
isAssignMent a
| a == "" = False
| (head trimmed) == '=' = True
| otherwise = False
where
trimmed = trimRightSide a [' ', '\n']
Guard clauses are checked sequentially. You only need an otherwise
clause at the very end.
Upvotes: 5
Reputation: 18189
You can also write this more idiomatically with pattern matching:
isAssignMent::String->Bool
isAssignMent "" = False
isAssignMent a
| '=':_ <- trimmed = True
| otherwise = False
where
trimmed = trimRightSide a [' ', '\n']
Upvotes: 5