caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Louis Giavitto <jean-louis.giavitto@ircam.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Contraintes dans la définitionrécursive de classes
Date: Fri, 18 Feb 2011 20:50:33 +0100	[thread overview]
Message-ID: <4D5ECD89.6060906@ircam.fr> (raw)

Bonjour.

Je rencontre le problème suivant : une définition récursive de classe 
contraint les types paramètres de la classe, plus que je ne le souhaiterais.

Je ne comprend pas d'où viennent ces contraintes supplémentaires. Voici 
un exemple minimal :

    class virtual ['a, 'b] base =
    object
      method virtual m : 'a -> 'b derive
    end

    and virtual ['a] derive =
    object
      inherit ['a, 'a] base
    end


le typage résultant donne :

   class virtual ['a, -'b] base1 :
   object
      constraint 'b = 'a
      method virtual m : 'a -> 'a derive1
   end
   and virtual ['a] derive1 :
   object
      method virtual m : 'a -> 'a derive1
   end


ce qui ne me permet pas d'avoir un 'b arbitraire.
Je peux plus ou moins contourner ce problème de la manière suivante :

    class virtual ['a, 'b, 'c] pre_base =
    object
      method virtual m : 'a -> 'c
    end

    class virtual ['a] derive =
    object
      inherit ['a, 'a, 'a derive] pre_base
    end

    class virtual ['a, 'b] base =
    object
      inherit ['a, 'b, 'b derive] pre_base
    end



dont le type est :

   class virtual ['a, 'b, 'c] pre_base :
   object
      method virtual m : 'a -> 'c
   end

   class virtual ['a] derive :
   object
      method virtual m : 'a -> 'a derive
   end

   class virtual ['a, 'b] base :
   object
      method virtual m : 'a -> 'b pre_derive
   end



J'imagine bien qu'il y a une histoire de généralisation de variable mais 
je ne comprend pas ce qui change fondamentalement quand on définit dans 
le même class ... and ... end


Merci de vos éclaircissements.
Jean-Louis Giavitto.

             reply	other threads:[~2011-02-18 19:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18 19:50 Jean-Louis Giavitto [this message]
2011-02-18 21:34 ` Guillaume Yziquel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D5ECD89.6060906@ircam.fr \
    --to=jean-louis.giavitto@ircam.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).