[Haskell-cafe] Re: a simple question about types

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Thu Nov 18 03:59:24 EST 2010


Daniel Fischer <daniel.is.fischer at web.de> writes:

> On Wednesday 17 November 2010 19:09:16, Jerzy M wrote:
>> Hallo,
>> let me take this simple function: (2*).
>> If I check its type
>>
>> :t (2*)
>>
>> I'll obtain
>> (2*) :: (Num a) => a -> a
>>
>> But now it suffices to write
>> g = (2*)
>> and check
>>
>> :t g
>>
>> to obtain
>> g :: Integer -> Integer
>>
>> One more combination, now I write
>> h x = (2*) x
>> and check once more
>>
>> :t h
>>
>> to get
>> h :: (Num a) => a -> a
>>
>> So my question is: why (in this second example) Integer is inferred?
>> What makes a difference?
>
> The monomorphism restriction.

And default. If you load this into ghci

   module Main where

   default (Int)

   g = (2*)
   main = putStrLn "foo"

and type :t g

you'll get Int -> Int

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk





More information about the Haskell-Cafe mailing list