Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Emmanuel Engel <Emmanuel.Engel@lri.fr>
To: caml-list@inria.fr
Subject: foncteurs et polymoprhisme
Date: Fri, 27 Jun 1997 14:48:25 +0200	[thread overview]
Message-ID: <33B3B699.141@lri.fr> (raw)

Il m'arrive souvent de vouloir definir des types de la forme

type expr =
   AC of Exprset.t
 | A of exp list 
 | .....


module Exprset = Set.make(struct type t = expr let compare = compare
end)

(en camllight, 
  type expr =	
    AC of expr set__t
   |A of expr list
   |....
)

cela n'est pas facilement possible en ocaml, les definitions incluant 
des modules ne peuvent etre ( mutuellement ) recursives.

Une methode possible est la traduction en ocaml de la solution
camllight:

type expr =
  AC of expr GeneriqueSet.t 
 |A of  expr list 
 |...                  

et definir des ensembles generiques.

Question:
    Existe-t-il un moyen simple et rapide a l'aide du foncteur 
  Set.Make de creer des ensembles polymorphes qui utilisent une
  fonction de comparaison generique (Pervasives.compare par exemple) ??

  eg 

  module GeneriqueSet = Set.Make(struct ?????? end)

Il me semble que non et, que cette impossibilite est plus due a la facon 
dont est declare le foncteur qui permet de construire les ensembles qu'a 
une vraie limite du systeme; voici une version legerement differente de
ce foncteur qui me permet une telle manip:

module Make(S:sig type 'a t val compare : 'a t -> 'a t -> int end)=
  (struct
     type 'a elt = 'a  S.t
     type 'a set = ('a elt) list
     let empty = []
     and mem = List.mem
     and add e s = e::s
  end:sig
	type 'a elt = 'a S.t
        and 'a set
        val empty : 'a set
        val mem : 'a elt -> 'a set -> bool
        val add : 'a elt -> 'a set -> 'a set
      end);;


module IntSet = Make(struct type 'a t = int let compare = (compare:int
-> int -> int) end);;
module GenericSet = Make(struct type 'a t = 'a let compare = compare
end);;




Commentaires ??


-- 

- Emmanuel Engel





                 reply	other threads:[~1997-06-27 16:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=33B3B699.141@lri.fr \
    --to=emmanuel.engel@lri.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