[Haskell-cafe] proposal: point free case expressions
Sebastiaan Visser
sfvisser at cs.uu.nl
Thu Nov 5 12:39:52 EST 2009
On Nov 5, 2009, at 6:26 PM, Jonathan Daugherty wrote:
>> So we could write:
>>
>>> myFunc = anotherFunc $ case of
>>> Left err -> print err
>>> Right msg -> putStrLn msg
>>
>> A minor syntactical addition, a big win!
>
> +1.
>
> While we're on the topic, what do people think of a related problem,
> case expressions over monadic values? I run into this often enough
> that it's a pain. I'd like to take
>
> result <- act1
> case result of
> ... -> actN
>
> and drop the bind entirely to get
>
> case act1 of
> ... -> actN
>
> I know that there are many helper functions and constructs to make
> this sort of thing more readable, but sometimes a case expression is a
> good fit and the preceding bind just ends up being noisy.
>
> --
> Jonathan Daugherty
I think your example is ambiguous in the sense that the case cannot
know whether it should pattern match on the entire `m a' or just on
the value `a' pulled out of the monad . Or maybe I don't entirely
understand your example.
With the proposed `case of' it would become something like this:
act1 >>= case of
... -> actN
Cheers,
Sebastiaan
More information about the Haskell-Cafe
mailing list