[Haskell-beginners] Is this MR? Type restriction confusion

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Thu Dec 17 18:35:32 EST 2009


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 at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20091217/78bdbd6b/PGP.bin


More information about the Beginners mailing list