Haskell: Multiple Case Statements in Single Function

后端 未结 3 821
故里飘歌
故里飘歌 2021-02-15 09:58

I want to include more than one case statement in a Haskell function (see below for an example of a hypothetical function).

However, it is not legal Haskell. What is a b

3条回答
  •  粉色の甜心
    2021-02-15 10:28

    I wouldn't use a case statement in this case though, this IMO looks better:

    tester :: Int -> String -> String
    tester x y | x < 0     = "less than zero. " ++ expr
               | otherwise = "greater than or equal to zero. " ++ expr
        where expr = if y == "foo" then "the name is foo." else "the name is not foo." 
    

提交回复
热议问题