Isn't this tail recursive?

Hal Daume III hdaume@ISI.EDU
Tue, 12 Mar 2002 16:28:37 -0800 (PST)


Oops, I made a false statement:

> > f $! a = f a
> 
> but the difference is that $! causes "a" to be reduced completely, so it
> won't build a huge thunk.

This isn't true.  $! will only perform one reduction, so for instance:

> id $! (a+1,b+1)

will not cause a+1 and b+1 to be calculated; it will only perform the
computation which creates the tuple.  similarly,

> id $! [a+5]

will not cause a+5 to be calculated, it will only result in the list being
created (i.e., reduced from a computation which will compute [a+5] to
simply the value [a+5]).  if you want what i was talking about, use the
DeepSeq module (http://www.isi.edu/~hdaume/haskell/Util/DeepSeq.hs) and
then you can write:

> id $!! [a+5]

which will actually perform the calculation.

 - Hal