[Haskell-beginners] Further constraining types
Thomas
haskell at phirho.com
Sat Aug 6 22:54:35 CEST 2011
> (==) (Natural a) (Natural b) | a == b = True
> | otherwise = False
Essentially the same, but I usually write this a little shorter as
(==) (Natural a) (Natural b) = a == b
> (Natural a) * (Natural b) | a < 0 || b < 0 = Indeterminate
> | otherwise = Natural ((Prelude.*) a b)
Why this? A 'Natural x' should already guarantee that 'x' is not
negative (otherwise it would be 'Indeterminate').
> Thoughts?
It seems very reasonable to me.
Regards,
Thomas
More information about the Beginners
mailing list