[Haskell-cafe] case of (was: [Haskell] Mixing monadic and
non-monadic functions)
Donn Cave
donn at drizzle.com
Mon Sep 19 18:24:03 EDT 2005
On Mon, 19 Sep 2005, Andrew Pimlott wrote:
> On Sat, Sep 17, 2005 at 06:56:36PM +0100, Ben Rudiak-Gould wrote:
> > * The new syntax is really nice as a replacement for the annoyingly
> > common "x <- foo ; case x of..." idiom that I've always disliked.
>
> I might wish for "case of" to mean "\x -> case x of":
>
> foo >>= case of ...
>
> Useful outside of monads, eg to write anonymous functions for map.
The ordinary lambda comes close - in ghc anyway, it supports
pattern matching. But I can't work out the syntax for multiple
cases, which would obviously be needed to make it practically
useful.
e.g., this seems to be OK:
getArgs >>= \ (a:_) -> putStrLn (show a)
but how do you write
getArgs >>= \ [] -> putStrLn "(no arguments)"
(a:_) -> putStrLn (show a)
(pardon me if I missed where you were going in "case of ...")
Donn Cave, donn at drizzle.com
More information about the Haskell-Cafe
mailing list