[Haskell-cafe] Strange subtract operator behavior - and lazy
john at repetae.net
Wed Oct 17 21:01:59 EDT 2007
On Wed, Oct 17, 2007 at 05:43:08PM -0700, David Benbennick wrote:
> This module doesn't appear to be very lazy to me. For example, in ghci,
> *Util.LazyNum List> genericLength (1:2:undefined) > (1 :: Nat)
> *** Exception: Prelude.undefined
> How is this module intended to be used?
Oops, sorry, the version I posted was an intermediate one that had a
different addition algorithm. here is a better one that fixes that issue:
Zero + y = y
Sum x n1 + y = Sum x (y + n1)
note that it alternates the order in the recursive call, interleaving
the elements of the two arguments.
so, this is head-strict in the left argument, but tail-lazy in both.
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell-Cafe