laziness, impatience, and hubris | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
To address this question more directly, I think it'd take very little to make this possible in Perl5. All that is required is a special function to mimic the ':' operator in Haskell. The crucial requirement for this operator is that its last operand not be evaluated unless it is specifically requested. In what I posted, I had to do this "by hand"; i.e. what should have been simply had to be recast into The business with memoize is in some sense not essential; this would have, in principle, worked too:
Wrapping the second argument with an anonymous sub effectively delays its evaluation. But without the memoization, this whole scheme becomes hopelessly bogged down with all the recursive calls. If perl did not evaluate the second argument of ll_new, then the whole implementation would look a lot cleaner. For example, the definition of $fibs above would go from: to the relatively pithy: which holds its own against the Haskell rendition of the same:
the lowliest monk In reply to Re: Hamming Sequences and Lazy Lists
by tlm
|
|