[Haskell-cafe] A first glimps on the {-# NOUPDATE #-} pragma
Thomas Schilling
nominolo at googlemail.com
Wed Aug 29 18:16:10 CEST 2012
On 29 August 2012 15:21, Joachim Breitner <breitner at kit.edu> wrote:
> Hi Facundo,
>
> Am Mittwoch, den 29.08.2012, 10:26 -0300 schrieb Facundo Domínguez:
> > > upd_noupd n =
> > > let l = myenum' 0 n
> > > in last l + length l
> >
> > This could be rewritten as
> >
> > > upd_noupd n =
> > > let l n = myenum' 0 n
> > > in last (l n) + length (l n)
> >
> > Or a special form of let could be introduced to define locally-scoped
> macros:
> >
> > > upd_noupd n =
> > > let# l = myenum' 0 n
> > > in last l + length l
> >
> > What's the strength of the {-# NOUPDATE #-} approach?
>
> it does not require refactoring of the code. There is not always a
> parameter handy that you can use to prevent sharing, and using () for
> that sometimes fails due to the full-lazyness-transformation.
>
> And a locally-scoped macros would not help in this case:
>
> test g n = g (myenum' 0 n)
>
> Now you still might want to prevent the long list to be stored, but here
> it cannot be done just by inlining or macro expansion.
>
Syntactically, I'd prefer something that looks more like a function. With
a pragma it's difficult to see what expression it actually affects. For
example, we already have the special functions "lazy" and "inline". Since
avoiding updates essentially turns lazy evaluation into call-by-name you
could call it "cbn". Perhaps that suggests a different use case, though, so
"nonstrict", "unshared", or "nonlazy" might be more self-explanatory.
I'd also like to point out that avoiding updates can dramatically improve
the kind of speedups my tracing JIT can achieve. In particular, on some
benchmarks, it can optimise idiomatic Haskell code to the same level as
stream fusion. I can simulate that by avoiding *all* updates (i.e., use
call-by-name), but that would break some programs badly. (Technically,
that's all legal, but I'm pretty sure it breaks any "tying-the-knot"
tricks.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120829/93c6f786/attachment.htm>
More information about the Haskell-Cafe
mailing list