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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] odd typing behavior
> Here is a boiled-down example of a problem that i can't figure out.
> Can anyone explain this ?
>
> thanks
> henri

That's a normal behavior : the compiler can't infer correctly the monorphic
type of the Hashtbl if this type have been declared after the instance is
created. (that's version 1 against 3). For version 2 , you're only defining
a type alias, not a new type, so there is no problem with that. Objects here
are not an issue, you can get the same behavior without them, but looks like
in this case the (more readable) error message is lost :

# let h = Hashtbl.create 0;;
val h : ('_a, '_b) Hashtbl.t = <abstr>
# type t = { x : int };;
type t = { x : int; }
# Hashtbl.add h 3 { x = 5 };;
Characters 16-25:
  Hashtbl.add h 3 { x = 5 };;
                  ^^^^^^^^^
This expression has type t but is here used with type 'a
The type constructor t would escape its scope

Regards,
Nicolas Cannasse

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners