[
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: | Tiphaine Turpin <Tiphaine.Turpin@i...> |
| Subject: | Re: [Caml-list] Open class types |
The behaviour of the compiler for your code is strange: I don't see why
the message error say the following:
#session_t as 'a = < id : int; location : 'b. #location_t; .. >
where location is required to be a #location_t for all 'b (which I
assume is the implicit self type variable of the open_type #location_t).
This seems to restrictive. Maybe a bug ?
Anymay, putting an explicit parameter in the session_t type solves the
issue:
class type ['a] session_t =
object
method id:int
method location: #location_t as 'a
end
let check_session (session:'a #session_t) = begin
print_int session#id;
print_int session#location#a;
print_string session#location#b
end
Tiphaine Turpin
SerP a écrit :
>
>
> class type location_t =
> object
> method a: int;
> method b: string;
> end;
>
> class type session_t =
> object
> method id:int;
> method location: #location_t;
> end;
>
> value check_session (session:#session_t) = begin
> print_int session#id;
> print_int session#location#a;
> print_string session#location#b;
> end;
>
> class location =
> object
> method a = 1;
> method b = "b";
> method c = ["a";"b"];
> end;
>
> class session =
> object value location = new location;
> method id = 1;
> method location = location;
> end;
>
> value _ =
> let s = new session in
> check_session s;
> ====================================
> Error: This expression has type session = < id : int; location :
> location >
> but is here used with type
> #session_t as 'a = < id : int; location : 'b. #location_t; .. >
> Type location = < a : int; b : string; c : string list >
> is not compatible with type 'b
> The second object type has no method c
> --------------------------------------------
> But,
> value check_session (session:< id : int; location : < a : int; b :
> string; .. >; .. >) = begin .....
>
> Compiled properly.
>
> Please help. Is exists any way to define open class type like inline
> type definition.
> Write every function with inline type definition in mli files is
> terrible.
>
>
> _______________________________________________
> 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
>