Version française
Home     About     Download     Resources     Contact us    
Browse thread
Open class types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: SerP <serp@s...>
Subject: Open class types


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.