
On 08/06/2011 12:54 PM, Thomas wrote:
(==) (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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
One more quick question: If I hide my actual constructors in favor of a smart constructor, is it no longer possible for me to do direct pattern matching on the values? E.g., the compiler does not allow this: analyze (Natural 5) = "It's a five!!!" ...so I have to do this: analyze a | natural 5 = "It's a five!!!" -- frigidcode.com theologia.indicium.us