[Haskell-cafe] Strange subtract operator behavior - and lazy naturals

Yitzchak Gale gale at sefer.org
Wed Oct 17 06:41:54 EDT 2007


John Meacham wrote:
> if anyone is interested, Although I bet this has been implemented a
> hundred times over, I have attached my lazy naturals module below just
> for larks.

Nice, lots of fun!

Wouldn't it be more convenient to allow them
to be signed? True, you can't have laziness in
certain cases, and certain calculations would
be non-convergent. But you already have
things like that, e.g subtraction, and natEven.

> Anyone have any comments on my lazy multiplication algorithm?

Looks fine to me. It introduces left-bias, but you have
to do it one way or the other.

> since (+) is lazy, we can still get a good lazy result without
> evaluating the tails when multiplying... that is nice.

Yes.

> n `mod` 0 should be?

It's negative infinity if n > 0, but you don't
allow negative numbers. I suppose it should
be Zero - in your implementation, Zero does
not exactly have the semantics of 0. Instead,
it means "either 0 or negative".

> If anyone wants me to clean this up and package it as a real module, I
> would be happy to do so.

Please at least post it to the wiki.

> sorry for the tangent. just one of those days.

I know the feeling... :)

Thanks,
Yitz


More information about the Haskell-Cafe mailing list