Hi all, I have a question about lazy evaluation. In the following function:
nco :: RealFloat a => a -> [ Complex a ] nco wn = 1 : map ((*) (cis wn)) (nco wn)
will the sin and cos associated with cis be evaluated once, or for each call? Thanks. -- Matthew Donadio (m.p.donadio@ieee.org)
For each call, I believe. An exception might be if the call to nco is inlined into the calling function, but this is unlikely as nco is recursive. 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. HTH. -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume On Sat, 11 Jan 2003, Matthew Donadio wrote:
Hi all,
I have a question about lazy evaluation. In the following function:
nco :: RealFloat a => a -> [ Complex a ] nco wn = 1 : map ((*) (cis wn)) (nco wn)
will the sin and cos associated with cis be evaluated once, or for each call?
Thanks.
-- Matthew Donadio (m.p.donadio@ieee.org) _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
participants (2)
-
Hal Daume III -
Matthew Donadio