Hi,
I also support Jon's proposal for standalone of { ... }. Seems to me clearer and more useful than the special "\case" construct.
I suppose 'of { ... }' could be generalized to multiple arguments, so that
of (Just x) (Just y) -> x ++ y
would create an anonymous function of type 'Maybe String -> Maybe String -> String'.
Considering the recent thread about partial functions:
we could have variants of 'of' to distinguish partial functions. For example, we could have something like 'ofFull' that would require an exhaustive list of patterns, and something like 'ofPart' that would instead produce results of type 'Maybe something'. (Most likely we'd have to think of better names for them.) For example:
ofPart [x] [y] -> x ++ y
[Perhaps we could have 'of' to work both ways - if the list of patterns would be exhaustive, the result would be pure. If it would be non-exhaustive, the result would be 'Maybe something'. Of course 'case x of ...' would still work as now, not caring about exhaustiveness. But I'm not sure if this wouldn't be too error prone.]
We could even generalize 'ofPart' to work with any Alternative instance so that
ofPart [x] [y] -> x ++ y
would be of type '(Alternative f) => [String] -> [String] -> f String'. Matching patterns would return results using 'pure', non-matching 'empty', and they would be all combined combined using <|>. 'empty' would be returned if nothing matched. (Among other things, this could have some interesting consequences when overlapping patterns would be applied to 'Alternative []'.) For example
fn = ofPart (Right 0) -> 1
(Right x) -> x
would produce (using today's syntax):
fn :: (Alternative f) => Either Bool Int -> f Int
fn x = case x of { Right 0 -> pure 1 ; _ -> empty; } <|>
case x of { Right x -> pure x ; _ -> empty; } <|>
empty
Best regards,
Petr