[Haskell-cafe] Re: monad subexpressions

Claus Reinke claus.reinke at talk21.com
Fri Aug 3 11:29:32 EDT 2007


>>> can you please rewrite *p++=*q++ in haskell?
>>     do { w p =<< r q; i p; i q }
> 
> how about *Object.File.Line.CurPtr++ = *AnotherObject.File.Line.CurPtr++  ? ;)

what's the difference?-)

    let p = Object.File.Line.CurPtr
    let q = AnotherObject.File.Line.CurPtr
    do { w p =<< r q; i p; i q }

the other line-noise version i gave does't even need the lets to 
avoid duplicating long names:

    i Object.File.Line.CurPtr =: (r `ap1` i AnotherObject.File.Line.CurPtr)

but this is rapidly approaching the level at which my brain calls for 
a separation of concerns. there are oneliners that make code more 
obvious, and there are oneliners that make code harder to read. and 
definitions of hard/obvious differ..
 
> the problem with Haskell is that we need to split C expression into
> several statements and explicitly specify execution order even when we
> know that it doesn't matter. ideally, it should be possible to define
> 
> ++x = modifyIORef x (+1) >> readIORef x
> *x  = readIORef x

apart from the prefix symbols (i used one-letter prefix names), you 
can (as i'm sure you know). and the point of my little exercise was to 
show that instead of doing the splitting by hand at each usage site, 
we can write lifting combinators that do the splitting behind the scenes.
what gives haskell aspirations to be a fine imperative language is that
its abstraction mechanisms work as well for imperative code as for
functional code.

claus




More information about the Haskell-Cafe mailing list