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
type troubles with functors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-06-22 (07:50)
From: Virgile Prevosto <virgile.prevosto@m...>
Subject: Re: [Caml-list] type troubles with functors
Le 06/22/2005, à 04:48:36 PM, Pietro Abate a écrit:
> module type OrderedType = sig
>       type t
>       val compare : t -> t -> int
> end
> module type S = sig
>       type elt
>       type t
>       type set
>       val to_list : t -> elt list
>       val to_set : t -> set
> end
> module Make (Ord : OrderedType) : S = struct

I guess it might be useful to have as signature
'S with type elt = Ord.t', otherwise the elements of the sets would be
abstract as well.
Another solution for the module type would be to export explicitely the
set module -with another type constraint stating that it manipulate
elements of the same type as S itself:

module type S = sig
    type elt
    module EltSet: Set.S with type elt = elt
    type t
    val to_list : t -> elt list
    val to_set: t -> EltSet.t

This way, you'll have access directly to all the functions provided in
Set.S, while with the above signature, you must write them explicitely
in the signature S in order to use them (but this also allows you to
restrict the operations that are allowed on values of EltSet.t, which is
not the case when exposing the whole module).

E tutto per oggi, a la prossima volta