Zulip Chat Archive

Stream: new members

Topic: is there pattern matching with guards


Shubham Kumar 🦀 (he/him) (Dec 20 2023 at 10:03):

I am looking for something like the following in Haskell and OCaml respectively

withinRange :: Int -> Bool
withinRange x
    | x >= 0 && x <= 10 = True
    | x >= 20 && x <= 30 = True
    | otherwise = False

and

let within_range = function
  | x when x >= 0 && x <= 10 -> true
  | x when x >= 20 &&  x <= 30 -> true
  | _ -> false

Last updated: Dec 20 2023 at 11:08 UTC