Haskell: Multiple Case Statements in Single Function

后端 未结 3 804
鱼传尺愫
鱼传尺愫 2021-02-15 10:06

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:26

    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." 
    

提交回复
热议问题