Evaluation Question

Tom Pledger Tom.Pledger@peace.com
Mon, 13 Jan 2003 08:29:47 +1300


Hal Daume III writes:
 :
 | So, you're probably better off with:
 |
 | > nco wn = nco'
 | >     where wn'  = cis wn
 | >           nco' = 1 : map (wn'*) nco'
 |
 | In which case it will only be evaluated once.

The following version also evaluates 'cis wn' only once.

 > nco wn = iterate (cis wn *) 1

I've only tested this in hugs with no command line flags, and can't 
explain the theory offhand.

 > import Complex()
 > import Trace
 > cis t  = trace "\ncis\n" (Complex.cis t)
 > nco wn = iterate (cis wn *) 1

    Main> take 5 (nco (pi/2))
    [1.0 :+ 0.0,
    cis
    (-4.37114e-08) :+ 1.0,(-1.0) :+ (-8.74228e-08),1.31134e-07 :+ 
(-1.0),1.0 :+ 1.74846e-07]

Regards,
Tom