[Haskell-cafe] Re: a regressive view of support for imperative programming in Haskell

David Roundy droundy at darcs.net
Thu Aug 9 14:56:59 EDT 2007


On Thu, Aug 09, 2007 at 08:45:14PM +0200, Benjamin Franksen wrote:
> David Roundy wrote:
> > Several times since reading the beginning of this discussion I've wished I
> > had the new syntax so I could write something like:
> > 
> >   do if predicateOnFileContents (<- readFile "foo") then ...
> > 
> > instead of either
> > 
> >   do contents <- readFile "foo"
> >      if predicateOnFileContents contents then ...
> > 
> > or (as you'd prefer)
> > 
> >   readFile "foo" >>= \contents ->
> >   if predicateOnFileContents contents then ...
> 
> Isn't this problem, namely being forced to name intermediate results, also
> solved by some sort of idiom bracket sugar, maybe together with the lambda
> case proposal? I would prefer both very much to the proposed (<- action)
> syntax for the same reasons that e.g. Jules Bean nicely summarized.

I'm not familiar with the lambda case proposal, and don't know what you
mean by idiom bracket sugar, but I haven't had an idea (or heard of one)
that was nearly so elegant as the (<- action) proposal, which neatly allows
one to lift any existing pure function or syntactic construct (except
lambda expressions?) into a monad.  i.e. we don't need to define a separate
'if', 'case', etc, and we don't need liftM, liftM2, liftM3, liftM4andahalf,
all of which are subsumed by a single pretty syntax.  The only cost is that
this syntax relies on the do notation, and thus makes the desugaring of
that do notation slightly more complicated when used.
-- 
David Roundy
Department of Physics
Oregon State University


More information about the Haskell-Cafe mailing list