Haskell syntax for 'or' in case expressions
问题 In F#, I can use | to group cases when pattern matching. For example, let rec factorial n = match n with | 0 | 1 -> 1 // like in this line | _ -> n * factorial (n - 1) What's the Haskell syntax for the same? 回答1: There is no way of sharing the same right hand side for different patterns. However, you can usually get around this by using guards instead of patterns, for example with elem. foo x | x `elem` [A, C, G] = ... | x `elem` [B, D, E] = ... | otherwise = ... 回答2: with guards: factorial n