[Haskell-cafe] Re: inversion lists
pumpkingod at gmail.com
Tue Dec 1 18:24:51 EST 2009
You probably don't want that minBound in the pattern, but rather as a
comparison in a guard.
On Tue, Dec 1, 2009 at 6:14 PM, Sjoerd Visscher <sjoerd at w3future.com> wrote:
> Hi Ted,
> Some tips:
>> invlist_negate  = 
>> 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!
> Sjoerd Visscher
> sjoerd at w3future.com
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe