Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] native code debugging
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Mentre <David.Mentre@i...>
Subject: False polymorphic (was: Re: [Caml-list] native code debugging)
JayR <jcriddle4@home.com> writes:

> # let id x = x;;
> val id : 'a -> 'a = <fun>

This expression is fully polymorphic.

# id 7;;
- : int = 7
# id "w";;
- : string = "w"


> # let id2 = id id;;
> val id2 : '_a -> '_a = <fun>

This one is not (notice the underscore (_) before the type variable
a). It is a monomorphic type that is right know unknown but will be
determined at first instantiation.

> # id2 7;;
> - : int = 7

# id2;;
- : int -> int = <fun>

You see, you now have int instead of '_a.

> # id2 "w";;
> This expression has type string but is here used with type int

So of course the type does not match with a string parameter.

For further information on this subject, have a look at the FAQ:
http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#variables_de_types_faibles 

Best regards,
d.
-- 
 David.Mentre@inria.fr
 Opinions expressed here are only mine.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr