Browse thread
annotations and type-checking
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Philippe <philippe.veber@g...> |
| Subject: | Re: [Caml-list] annotations and type-checking |
Le 29 juil. 09 à 01:28, Jon Harrop <jon@ffconsultancy.com> a écrit : > On Tuesday 28 July 2009 22:47:25 Aaron Bohannon wrote: >> let f (x : 'a) : 'a = x in (f true, f 3);; > > Err, good question. :-) > > # let f : _ = fun x -> x in f true, f 3;; > - : bool * int = (true, 3) The type of f here is something like 'a. 'a -> 'a. So you can use it on bool or int. I understand it like [], like in the expression (3 :: [], true :: []) where it has type 'a. 'a list (unfortunately it is not synctacally correct to say let f : 'a. 'a -> 'a = fun x -> x, I don't know why.) > > # let f : 'a = fun x -> x in f true, f 3;; > Error: This expression has type int but is here used with type bool Here you specify that there exists a type named 'a, which is the return type of f and which should unify with both bool and int. Hence the typing error. > > > I'm guessing the scope of the 'a is not what you'd expect but I have > no idea > why. I'd have thought the latter would be a harmless type > annotation... My guess is that the problem here is not about scope but about quantifiers : the type of f is quantified universally by default but the annotation constrains the type of f to a fixed (yet unknown) type in the subsequent expression (in that sense, yes, the scope of f plays a crucial role). HTH, Ph. > > > Any takers? > > -- > Dr Jon Harrop, Flying Frog Consultancy Ltd. > http://www.ffconsultancy.com/?e > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs