<p>The 1 is not necessarily an Integer nor is it necessarily a Float, Double<br>
or Rational. GHC applies so called type-defaulting rules to make a<br>
best guess in this scenario. Informally, if it could be an Integer (due<br>
to lack of static evidence to the contrary), then you can expect the<br>
defaulting rules to assign it that type.</p>
<p>--<br>
Jason Dusek<br>
</p>
<div class="gmail_quote">On Apr 5, 2012 7:45 AM, <<a href="mailto:j.romildo@gmail.com">j.romildo@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Thu, Apr 05, 2012 at 01:18:39PM +0000, Amy de Buitléir wrote:<br>
> <j.romildo <at> <a href="http://gmail.com" target="_blank">gmail.com</a>> writes:<br>
> > Why does (read "2" + 1) works, but (read "2.3" + 1) fail at runtime?<br>
><br>
> Try this:<br>
><br>
> read "2.3" + 1 :: Float<br>
><br>
> Or this:<br>
><br>
> read "2.3" + 1.0<br>
><br>
> The reason that your version didn't work is because GHCi is guessing that you<br>
> want the read operation to parse an Integer, since you're adding it to 1.<br>
<br>
This is explanation does not seem to be enough once we consider the type<br>
of the literal 1:<br>
<br>
Prelude> :t 1<br>
1 :: Num a => a<br>
<br>
That is, the literal 1 is overloaded to any numeric type. It is not<br>
necessarily an Integer.<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>