haskell
2014-11-02 60 views 1 likes 
1

你好,我试图用鳞片状的条件,但我得到解析错误:哈斯克尔多个否则

parse error on input ‘|’ 

isAssignMent::String->Bool 
isAssignMent a 
    | a == "" = False 
    | otherwise 
     | (head trimmed) == '=' = True 
     | otherwise = False 
     where 
      trimmed = trimRightSide a [' ', '\n'] 

我在做什么错?谢谢

+0

'otherwise'只是为TRUE; – Squidly 2014-11-05 14:47:01

回答

5

这是你想要的吗?

isAssignMent::String->Bool 
isAssignMent a 
    | a == "" = False 
    | (head trimmed) == '=' = True 
    | otherwise = False 
     where 
      trimmed = trimRightSide a [' ', '\n'] 

Guard条款按顺序检查。您最终只需要otherwise条款。

+0

的代名词这解决了这个问题,谢谢 – yonutix 2014-11-02 23:14:07

5

您还可以更地道与模式匹配这样写:

isAssignMent::String->Bool 
isAssignMent ""   = False 
isAssignMent a 
    | '=':_ <- trimmed = True 
    | otherwise   = False 
    where 
     trimmed = trimRightSide a [' ', '\n'] 
相关问题