[Haskell-cafe] Re: monad subexpressions

David Roundy droundy at darcs.net
Fri Aug 3 15:13:18 EDT 2007


On Fri, Aug 03, 2007 at 02:41:05PM +0200, Mirko Rahn wrote:
> >>>rewrite *p++=*q++ in haskell?
> 
> >it's one of C idioms. probably, you don't have enough C experience to
> >understand it :)
> 
> Maybe, but how can *you* understand it, when the standard is vague about it?
> 
> It could be
> 
> A: *p=*q; p+=1; q+=1;
> B: *p=*q; q+=1; p+=1;
> C: tp=p; tq=q; p+=1; q+=1; *tp=*tq;
> 
> ...and so on. Which is the "right" version?

Isn't that the point? It's buggy code if *q == p or *p == q, or a few other
cases perhaps, but if those are not the case, then all of those are
"right," and the compiler has the choice to implement whichever it deems
most efficient.

In the cases where this is actually used, all three of those are correct,
the code is understandable, compact and unambiguous.
-- 
David Roundy
Department of Physics
Oregon State University


More information about the Haskell-Cafe mailing list