[Haskell-beginners] Type of function with constant pattern
tim.v2.0 at gmail.com
Tue Apr 10 23:16:15 CEST 2012
I believe that "f 0 = ..." is a guard and the guard is pattern matching on
the constructor. Despite the fact that you don't have an instance of "f _ =
....", the compiler needs an Eq instance to determine if it should run the
"f 0" version of the function.
Does that make sense? Hopefully someone with a better grasp of the topic
will fill in the details.
On Tue, Apr 10, 2012 at 12:57 PM, <j.romildo at gmail.com> wrote:
> Given the following function definitions
> f 0 = True
> g False = True
> ghc infers the following types for the functions:
> f :: (Eq a, Num a) => a -> Bool
> g :: Bool -> Bool
> Why f has "Eq a" in the context in ts type, and g does not?
> As both are defined using a constant pattern, I expected none of them
> should require the type of the argument to be instance of Eq.
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners