How can I make a counter without Monad?

Peter Davis pediddle at pediddle.net
Wed Mar 16 15:34:00 EST 2005


On 2005-03-16 02:52:39 -0800, Nicolas Oury <Nicolas.Oury at lri.fr> said:

> instance Splittable Integer where
>    split n = (2*n,2*n+1)
> 
> 
> foo::(%x::Integer) => [a] -> [(a,Integer)]
> foo [] = []
> foo (a:l) = (a,%x):(foo l)
> 
> test = let %x = 1 in foo [1..15000]
> 
> But, in this example, the numbering is linear and so test becomes quadratic.
> The main complexity of the program come from the numbering...
> (When you test it with ghci, this example is really slow)

I haven't played much with the Splittable class yet, but what would be 
wrong with

instance Splittable Integer where
   split n = (n,n+1)

?

-- 
Peter Davis <pediddle at pediddle.net>
"Furthermore, I believe bacon prevents hair loss!"




More information about the Glasgow-haskell-users mailing list