<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jul 29, 2011, at 9:49 AM, Jake Penton wrote:</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Well, there have been a couple of answers on this thread that suggest that a constraint/context will work. But this does not clear things up entirely for me. I probably do not understand your answer. But adding a constraint by itself does not of itself change things, although perhaps you are not suggesting that it would.&nbsp;</div><div><br></div><div>For example, this does not compile:</div><div><br></div><div><font class="Apple-style-span" color="#8F1792">f :: Fractional a =&gt; a</font></div><div><font class="Apple-style-span" color="#8F1792">f = 3.14</font></div></div></blockquote><div><br></div><div>It should. &nbsp;Is there something else in the file you're compiling which somehow conflicts? &nbsp;What error does it print?</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>This does:</div><div><br></div><div><font class="Apple-style-span" color="#8F1792">class Foo a where</font></div><div><font class="Apple-style-span" color="#8F1792">&nbsp;&nbsp; &nbsp;f :: Fractional a =&gt; a</font></div><div><font class="Apple-style-span" color="#8F1792"><br></font></div><div><font class="Apple-style-span" color="#8F1792">instance Foo Float where</font></div><div><font class="Apple-style-span" color="#8F1792">&nbsp;&nbsp; &nbsp;f = 3.14</font></div><div><br></div><div>So I infer that the reason that my example int the original post compiles is something other than merely the presence of the constraint. This compiles:</div><div><br></div><div><font class="Apple-style-span" color="#8F1792">f :: Num a =&gt; a</font></div><div><font class="Apple-style-span" color="#8F1792">f = 1</font></div></div></blockquote><br></div><div>Actually, it is solely the presence of the constraint which makes it OK. &nbsp;By constraining it, you're saying "f can produce a value of any type, so long as that type implements Num" - and by saying that, you get to rely on the compiler enforcing it, so you can use all the functions Num provides. &nbsp;One of those functions is "fromInteger", which the compiler uses in the implementation of "1". &nbsp;When you say "f = 1", the compiler interprets that as "f = fromInteger (1 :: Integer)". &nbsp;Without the constraint, you're not allowed to use "fromInteger" because that function doesn't exist for all types.</div><br><div>-- James</div></body></html>