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
Sparse structure
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-07-08 (23:29)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Sparse structure
From: Chris King <colanderman@gmail.com>

> > module Int = struct type t = int let compare : int -> int -> int = compare end
> > module M = Map.Make(Int)
> > type +'a elt
> > type 'a map = 'a elt M.t
> Thanks, that works great!  I'm curious though, what is the purpose of
> the elt type?  Is it to enforce the use of the map type instead of
> M.t?

Not exactly. [map] is only an abbreviation, used to shorten types in
the rest of the code. [elt] is more fundamental: it both hides the
contents of the map, by being abstract (so you can only access them
through Obj.magic), and has a type parameter which will be used to
enforce the relation between key and data type.

By the way, I've started experimenting with a camlp4 syntax extension
for that, and it seems to works nicely. I'll post it when it gets

Jacques Garrigue