patch applied (haskell-prime-status): add ""Make $ left associative, like application"

Dan Doel dan.doel at
Wed Apr 23 07:03:10 EDT 2008

On Wednesday 23 April 2008, Bulat Ziganshin wrote:
> Hello Dan,
> Wednesday, April 23, 2008, 1:42:20 PM, you wrote:
> > This wouldn't work, you'd have to rewrite it as:
> >
> >     withSomeResource foo .
> >       withSomeOtherThing bar .
> >         yetAnotherBlockStructured thing $ ...
> it is very inconvenient - we should use either . or $ depending on
> that it's last block or not. imagine all the changes when editing the
> code

Well, that may be inconvenient, but I don't know how much such block 
structured code is actually a composition of such functions. Off the top of 
my head, I'd expect most to involve lambdas or dos:

    forM l $ \e -> ...
    State $ \s -> ... (see also Reader, Cont, ...)
    runST $ do ... (or 'flip runM arg' for most monads, I suppose)
    callCC $ \k -> ... (shift)
    forever $ do ...
    withResource $ \r -> ...
    local f $ do ...

Which still work with the flipped associativity. The one oddity I noticed 
looking at random code of mine is reset in Cont(T), which might currently be 
used like:

    reset $ forM l $ \e -> ...

for inverting loops. It would have to become:

    reset . forM l $ \e -> ...

Which might be a little weird (of course, in CC-delcont, that's

    reset $ \p -> forM l $ \e -> ...

so it's moot there, but I suppose this affects all the functions that rely 
on 'do' to use repeated ($)s).

My code may well be abnormal, though (certainly, my infatuation with 
continuations probably is :)).

When I do have composition pipelines that don't fit on one line (like the 
initial example), I think I tend to write them like this:

    pipe = foo
             . bar
             . baz
             . quux
             $ quuux

Which lets you slip new things in pretty naturally, I think.

There may be a lot of code out there that that all doesn't work for, though. I 
don't know.
-- Dan

More information about the Haskell-prime mailing list