
On Dec 17, 2009, at 17:56 , Mike Erickson wrote:
f1a x = map (*x) -- has type (Num a) => a -> [a] -> [a]
f1b = \x -> map (*x) -- has type Integer -> [Integer] -> [Integer]
Can someone help me understand why the latter has a more restrictive type?
That is indeed the monomorphism restriction. In very short: if a top level form (like your f1, f1a, f1b) takes no arguments and does not have an explicit type, its type is restricted according to defaulting; if no suitable default exists, it is rejected. In this case, defaulting gave it the type Integer because Integer is the first type in the defaults list that allows the declaration to typecheck. (The default "defaults list" is Integer, Double, and in recent GHC () (the null/unit type). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH