[Haskell-cafe] Re: inversion lists

Daniel Peebles 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.

Dan

On Tue, Dec 1, 2009 at 6:14 PM, Sjoerd Visscher <sjoerd at w3future.com> wrote:
> 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
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list