[Haskell-beginners] Overloading resolution with numbers
damodar kulkarni
kdamodar2000 at gmail.com
Thu Apr 5 17:00:40 CEST 2012
On Thu, Apr 5, 2012 at 8:29 PM, damodar kulkarni <kdamodar2000 at gmail.com>wrote:
> See this:
> Prelude> :t 2.3
> 2.3 :: Fractional a => a
>
> Hope this helps.
>
>
>
> On Thu, Apr 5, 2012 at 7:24 PM, <j.romildo at gmail.com> wrote:
>
>> On Thu, Apr 05, 2012 at 01:18:39PM +0000, Amy de Buitléir wrote:
>> > <j.romildo <at> gmail.com> writes:
>> > > Why does (read "2" + 1) works, but (read "2.3" + 1) fail at runtime?
>> >
>> > Try this:
>> >
>> > read "2.3" + 1 :: Float
>> >
>> > Or this:
>> >
>> > read "2.3" + 1.0
>> >
>> > The reason that your version didn't work is because GHCi is guessing
>> that you
>> > want the read operation to parse an Integer, since you're adding it to
>> 1.
>>
>> This is explanation does not seem to be enough once we consider the type
>> of the literal 1:
>>
>> Prelude> :t 1
>> 1 :: Num a => a
>>
>> That is, the literal 1 is overloaded to any numeric type. It is not
>> necessarily an Integer.
>>
>> Romildo
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
>
> --
> Thanks and regards,
> -Damodar Kulkarni
>
>
--
Thanks and regards,
-Damodar Kulkarni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120405/2e14bdd4/attachment.htm>
More information about the Beginners
mailing list