English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
storing object in record
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-04-08 (07:36)
From: Michael <micha-1@f...>
Subject: storing object in record

it seems that I'm not able to figure out how to do  this:

class baseclass = object(this)
  method asBase = (this :> baseclass)
(* ... *)	

class ex = object inherit baseclass method name = "ex" end

type state_rec = { mutable state:  'a. #baseclass as 'a };;

this gives an error:

let x = new ex;;

{ state = x };;
Error: This field value has type ex which is less general than
         'a. #baseclass as 'a


{ state = x#asBase };;
Error: This field value has type baseclass which is less general than
         'a. #baseclass as 'a


type state_rec = { mutable state:  'a. < asBase: baseclass;..> as 'a };;
Error: Unbound type parameter ..

what I'm missing here?