[Haskell-beginners] can somebody explain the type of this expression?

Brandon Allbery allbery.b at gmail.com
Mon Oct 27 20:54:20 UTC 2014


On Mon, Oct 27, 2014 at 4:47 PM, Ovidiu Deac <ovidiudeac at gmail.com> wrote:

> Since the definition of expr looks like this:
> Prelude> let f x = x * 2
>
> ...and 2 is an Int, I would expect that the type inferred for (*)  is (Int
> -> Int -> Int) and thus f should be (Int -> Int)
>

    Prelude> :t 2
    2 :: Num a => a

Numeric literals are polymorphic.
http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1360006.4.1
is the official specification of this.

-- 
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/20141027/554ebcb3/attachment.html>


More information about the Beginners mailing list