[Haskell-beginners] Overloading resolution with numbers

Marius Ghita mhitza at gmail.com
Thu Apr 5 15:19:11 CEST 2012


Because this works

Prelude> read "2.3" + 1.0
3.3

Seriously I can only assume that via the inference it decides based on the
one that the string must be of type Int and uses the Read instance of Int
to parse it; whereas that string is obviously a float.

That is what* I think* it does.

On Thu, Apr 5, 2012 at 4:16 PM, <j.romildo at gmail.com> wrote:

> Hello.
>
> Consider the following ghci session:
>
>   Prelude> :t read "2" + 1
>   read "2" + 1 :: (Num a, Read a) => a
>
>   Prelude> :t read "2.3" + 1
>   read "2.3" + 1 :: (Num a, Read a) => a
>
>   Prelude> read "2" + 1
>   3
>
>   Prelude> read "2.3" + 1
>   *** Exception: Prelude.read: no parse
>
> Why does (read "2" + 1) works, but (read "2.3" + 1) fail at runtime?
>
> Romildo
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Google+: https://plus.google.com/111881868112036203454
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120405/1350a43e/attachment.htm>


More information about the Beginners mailing list