Version française
Home     About     Download     Resources     Contact us    
Browse thread
Polymorphic method and polymorphic type
[ 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: Polymorphic method and polymorphic type
Simple example. All functions are fake.

class getter = object method add_some p = p+1 end;;
type 'a get_mode = [ `Read | `Watch of (#getter as 'a)];;
let string_of_get_mode (gm: 'a get_mode) = match gm with `Read -> "Read" 
| `Watch g -> let i = g#add_some 1 in ("Watch "^ (string_of_int i));;
class c = object method pgm : 'a. ('a get_mode) -> string = 
string_of_get_mode end;;
--------------
This expression has type 'a. (#getter as 'a) get_mode -> string
but is here used with type 'b. (#getter as 'b) get_mode -> string
Type #getter as 'c = < add_some : int -> int; .. >
is not compatible with type 'c

====================
Please help. Is it my error? how should we do that the right way?