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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sylvain BOULM'E <Sylvain.Boulme@l...>
Subject: Re: OCAML parametric class coercion
In OCAML objects system, polymorphic methods are forbidden (for the 
decidability of the type inference) : only classes may be polymorphic. So, you 
have to bind types of methods to types parameters of classes (it's a kind of 
skolemistation). For instance :

# class ['a] bidu1(dev) =
  object(self)
    method rate(untruc:'a) = untruc#essai
end;;
 

class ['a] bidu1 :
  'b -> object constraint 'a = < essai : 'c; .. > method rate : 'a -> 'c end

The system inferred the most general type, preventing an execution of 
"segmentation fault". Here, it adds a constraint ... But, you may also 
constraint by yourself this parameter (for a better readibility of code and 
inferred types, or semantic reasons about your classes) :

# class ['a] bidu2(dev) =
 object(self)
    constraint 'a = 'c #truc
    method rate(untruc:'a) = untruc#essai
 end;;

class ['a] bidu2 :
  'b -> object constraint 'a = 'c #truc method rate : 'a -> int end
 

# class ['a] bidu3(dev:'b) =
  object(self)
    constraint 'a = 'b #truc
    method rate(untruc:'a) = untruc#essai
  end;;

class ['a] bidu3 :
  'b -> object constraint 'a = 'b #truc method rate : 'a -> int end



Yours,

Sylvain.