Q: Forcing repeated evaluation

Adrian Hey ahey@iee.org
Fri, 20 Sep 2002 09:29:52 +0100


On Wednesday 18 September 2002 11:21 am, Simon Marlow wrote:
> > From: D. Tweed [mailto:tweed@compsci.bristol.ac.uk]
> >
> > Note that (assuming that I'm not missing something) you can
> > prevent the
> > moving of expressions involving l in a very ugly way by
> > noting that these
> > `dummy argument functions' are polymorphic so that you could write
> >
> > x1 = f1 (l 1)
> > x2 = f2 x1 (l 2)
> > x3 = f3 x2 (l 3)
>
> Please don't encourage this sort of thing.  If two expressions are
> semantically equivalent, there's always a chance that the compiler will
> replace one by the other or common them up.
>
> In this case, I believe GHC's worker-wrapper transformation will do it.

I still think it's a real problem though. With Haskell as it is at the
moment there seems to be no alternative to these ugly (and unreliable)
hacks. Clean allows programmers to distinguish between constants and
"functions" with zero arguments. Couldn't Haskell be modified to do
the same?

e.g. Instead of writing..
> squares = [i*i| i <- [1..]]

..we explicitly specify a function with no
arguments (implying no sharing allowed).
> squares = \ -> [i*i| i <- [1..]]

I'm not sure what the semantic consequences of this would be,
or even if the concept of 'sharing' has any sensible meaning
in Haskell. (There's probably an implicit assumption here that
all Haskell implementations will be based on some kind of graph
reduction, which isn't necessarily so.)

Regards
--
Adrian Hey