[Haskell-cafe] Re: inversion lists

Sjoerd Visscher sjoerd at w3future.com
Tue Dec 1 18:14:58 EST 2009


Hi Ted,

Some tips:
> invlist_negate [] = [0]
> invlist_negate (0:xs) = xs
> invlist_negate xs = 0:xs

You are doing this for generic Num instances, so 0 probably isn't the lower bound. Haskell has another type class for this: Bounded. Then you can use minBound instead of 0. Also the first line is just a special case of the last one.

invlist_negate :: (Bounded a, Num a) => [a] -> [a]
invlist_negate (minBound : xs) = xs
invlist_negate xs = minBound : xs

Try doing invlist_member together with a function invlist_notMember (just like there is notElem for lists), I think that would clean things up a bit.

Keep on going, there's lots of fun ahead!

greetings,
Sjoerd

--
Sjoerd Visscher
sjoerd at w3future.com





More information about the Haskell-Cafe mailing list