Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* OCAML parametric class coercion
@ 1999-05-30 20:24 Olivier Chararas
  1999-05-31 10:57 ` Sylvain BOULM'E
  1999-06-01  4:44 ` Benoit deBoursetty
  0 siblings, 2 replies; 3+ messages in thread
From: Olivier Chararas @ 1999-05-30 20:24 UTC (permalink / raw)
  To: caml-list

(*
NAIVE REQUEST :
In this design the ellipsis won't be bound so I wanted to use coercion
but I can't figure out how to express the coercion with respect to
the parametric type.

Can you help me on syntax?
Or is the problem more fundamental?
Is this bad design anyway?

Thanks
*)

# class ['a] truc(init,(dev:'a)) =
  object(self)
   method essai = 1
  end
  ;;
class ['a] truc : 'b * 'a -> object method essai : int end
# 
  class ['a] bidu1((dev:'a)) =
  object(self)
   method rate(untruc) = untruc#essai
  end
  ;;
Some type variables are unbound in this type:
  class ['a] bidu1 : 'a -> object method rate : < essai : 'b; .. > -> 'b
end
The method rate has type < essai : 'a; .. > -> 'a where .. is unbound
# 
  class ['a] bidu2((dev:'a)) =
  object(self)
   method rate(untruc:truc) = untruc#essai
  end
  ;;
The type constructor truc expects 1 argument(s),
but is here applied to 0 argument(s)




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: OCAML parametric class coercion
  1999-05-30 20:24 OCAML parametric class coercion Olivier Chararas
@ 1999-05-31 10:57 ` Sylvain BOULM'E
  1999-06-01  4:44 ` Benoit deBoursetty
  1 sibling, 0 replies; 3+ messages in thread
From: Sylvain BOULM'E @ 1999-05-31 10:57 UTC (permalink / raw)
  To: caml-list

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.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: OCAML parametric class coercion
  1999-05-30 20:24 OCAML parametric class coercion Olivier Chararas
  1999-05-31 10:57 ` Sylvain BOULM'E
@ 1999-06-01  4:44 ` Benoit deBoursetty
  1 sibling, 0 replies; 3+ messages in thread
From: Benoit deBoursetty @ 1999-06-01  4:44 UTC (permalink / raw)
  To: Olivier Chararas; +Cc: caml-list



On Sun, 30 May 1999, Olivier Chararas wrote:

> # class ['a] truc(init,(dev:'a)) =
>   object(self)
>    method essai = 1
>   end
>   ;;
> class ['a] truc : 'b * 'a -> object method essai : int end
> # 
>   class ['a] bidu1((dev:'a)) =
>   object(self)
>    method rate(untruc) = untruc#essai
>   end
>   ;;
> Some type variables are unbound in this type:
>   class ['a] bidu1 : 'a -> object method rate : < essai : 'b; .. > -> 'b
> end
> The method rate has type < essai : 'a; .. > -> 'a where .. is unbound
> # 
>   class ['a] bidu2((dev:'a)) =
>   object(self)
>    method rate(untruc:truc) = untruc#essai
>   end
>   ;;
> The type constructor truc expects 1 argument(s),
> but is here applied to 0 argument(s)

Ben ca, ca marche, je ne sais pas si c'est ce que tu cherches...
This works, I don't know if it's what you were looking for...

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

Benoit de Boursetty
Benoit.de-Boursetty@polytechnique.fr





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-06-01 15:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-30 20:24 OCAML parametric class coercion Olivier Chararas
1999-05-31 10:57 ` Sylvain BOULM'E
1999-06-01  4:44 ` Benoit deBoursetty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox