Using guards in let .. in expressions

后端 未结 2 2148
[愿得一人]
[愿得一人] 2021-02-18 15:35

Sometimes I write code like this

solveLogic :: Int -> Int -> Int
solveLogic a b =
    let 
        x = 1
        brainiac
            | a >= x     = 1
          


        
相关标签:
2条回答
  • 2021-02-18 16:27

    When I want guards as an expression I use this somewhat ugly hack

    case () of
    _ | a >= x     -> 1
      | a == b     -> 333
      | otherwise  -> 5
    
    0 讨论(0)
  • 2021-02-18 16:33

    Yes, using a where clause:

    solveLogic a b
            | a >= x     = 1
            | a == b     = 333
            | otherwise  = 5
        where
          x = 1
    
    0 讨论(0)
提交回复
热议问题