caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: SerP <serp@stork.ru>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Open class types
Date: Tue, 01 Jul 2008 17:53:34 +0400	[thread overview]
Message-ID: <486A36DE.4040605@stork.ru> (raw)



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.



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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-01 13:53 SerP [this message]
2008-07-01 15:02 ` [Caml-list] " Tiphaine Turpin
2008-07-01 15:14 ` 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=486A36DE.4040605@stork.ru \
    --to=serp@stork.ru \
    --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).