The case of
pattern matching can assist me in defining distinct actions for specific types that match a given pattern. However, the syntax doesn’t seem to support handling multiple matched patterns with a single action.
For example,
data T = A|B|C
run :: T -> IO ()
run t =
case t of
A -> putStrLn "A"
B -> putStrLn "B"
C -> putStrLn "C"
I am unable to write something like the following:
case t of
A,B -> putStrLn "A|B" -- compile error
C -> putStrLn "C
In my experience with Rust and OCaml, this functionality was present in both languages. I have attempted to find a way to accomplish this in Haskell, but it appears to be quite challenging. Can anyone provide assistance?
Thank you.