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.<div>
<br>Does that make sense? Hopefully someone with a better grasp of the topic will fill in the details.</div><div><br></div><div>--Tim<br><br><div class="gmail_quote">On Tue, Apr 10, 2012 at 12:57 PM, <span dir="ltr"><<a href="mailto:j.romildo@gmail.com">j.romildo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello.<br>
<br>
Given the following function definitions<br>
<br>
f 0 = True<br>
<br>
g False = True<br>
<br>
ghc infers the following types for the functions:<br>
<br>
f :: (Eq a, Num a) => a -> Bool<br>
g :: Bool -> Bool<br>
<br>
Why f has "Eq a" in the context in ts type, and g does not?<br>
<br>
As both are defined using a constant pattern, I expected none of them<br>
should require the type of the argument to be instance of Eq.<br>
<br>
Romildo<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>