caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Tiphaine Turpin <Tiphaine.Turpin@irisa.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Open class types
Date: Tue, 01 Jul 2008 17:02:27 +0200	[thread overview]
Message-ID: <486A4703.6040505@irisa.fr> (raw)
In-Reply-To: <486A36DE.4040605@stork.ru>

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
>


  reply	other threads:[~2008-07-01 15:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-01 13:53 SerP
2008-07-01 15:02 ` Tiphaine Turpin [this message]
2008-07-01 15:14 ` [Caml-list] " Virgile Prevosto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=486A4703.6040505@irisa.fr \
    --to=tiphaine.turpin@irisa.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).