[Haskell-beginners] Addition of "Float" and "Int".

Brandon Allbery allbery.b at gmail.com
Mon May 12 16:28:32 UTC 2014


On Mon, May 12, 2014 at 11:44 AM, Venu Chakravorty <c.venu at aol.com> wrote:

> Prelude> :t (+)
> (+) :: (Num a) => a -> a -> a
>
>  What I understand from the above is that "+" is a function that takes
> two args
> which are types of anything that IS-AN instance of "Num" (Int, Integer,
> Float, Double)
> and returns an instance of "Num".
>

Not exactly. It says that, given some type a that is an instance of Num, it
will add two values of that type and produce a new value of that same type.
You cannot mix and match types; it always works on some specific type,
although those types may change between uses of (+).

This is somewhat hidden by the way numeric literals are handled: a literal
without a decimal point is handled as if you had wrapped it in
fromIntegral, and one with a decimal point is handled as if you had wrapped
it in fromRational.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140512/bcffd5f6/attachment.html>


More information about the Beginners mailing list