Relation between functors and polymorphism

Christophe Raffalli (raffalli@cs.chalmers.se)
Wed, 3 Apr 1996 11:59:24 +0200 (MET DST)

Date: Wed, 3 Apr 1996 11:59:24 +0200 (MET DST)
Message-Id: <199604030959.LAA25846@lips.cs.chalmers.se>
From: Christophe Raffalli <raffalli@cs.chalmers.se>
To: caml-list@pauillac.inria.fr
Subject: Relation between functors and polymorphism

Hi,

I have a question that arise in the following circonstances:
I modified the Hashtbl library to make it a function taking a "key structure"
containing a type "key" a function "hash : key -> int" and a function "eq :
key -> key -> bool". Then I wondered how I could use the polymorphic hash and
equality functions to recover the original polymorphic Hashtbl structure.

You can generalize the question to:

What is the relation between a functor that only depends on one type (or more)
like

module A (B : sig type t end) = struct
type u = Some of B.t | None

let read = function
Some x -> x
| None -> raise Not_found
end

and a polymorphic structure like

module A' = struct
type 'a u = Some of 'a | None

let read = function
Some x -> x
| None -> raise Not_found
end

They look isomorphic ?

---

You can easely go from A' to A (This is quite verbose but you don't have to rewrite the types or functions definitions):

module A (B : sig type t end) = struct type u = B.t A'.u

let read = (A'.read : u -> B.t) end

But how can you reconstruct A' from A without rewriting the type or function definitions. Is this impossible ?

---- Christophe Raffalli Dept. of Computer Sciences Chalmers University of Technology

URL: http://www.logique.jussieu.fr/www.raffalli