From: Markus Mottl <mottl@miss.wu-wien.ac.at>
Message-Id: <199901161221.NAA00134@miss.wu-wien.ac.at>
Subject: Problem binding type parameters in modules
To: caml-list@inria.fr (OCAML)
Date: Sat, 16 Jan 1999 13:21:35 +0100 (MET)
Hello,
sometimes one has the impression that there must be a simple solution,
but one can just not see it...
My problem (example code):
---------------------------------------------------------------------------
module type FOO1 =
sig
type 'a foo
val empty : 'a foo
end
module type FOO2 =
sig
type foo
val empty : foo
end
(* ok *)
module Foo1 : FOO1 =
struct
type 'a foo = 'a list
let empty = []
end
(* also ok *)
module Foo2 : FOO2 =
struct
type foo = int list Lazy.t
let empty = lazy []
end
(* not ok *)
module Bar : FOO1 =
struct
type 'a foo = 'a list Lazy.t
let empty = lazy []
end
---------------------------------------------------------------------------
The compiler will report an error, because it does not infer the type of
"empty" in module "Bar" as specified in "FOO1".
No matter what I have tried, I haven't succeed in binding the type
parameter needed in "empty" to "'a" in type "foo", so that the module
signatures would match. E.g.:
---------------------------------------------------------------------------
(* also not ok *)
module Bar : FOO1 =
struct
type 'a foo = 'a list Lazy.t
let empty : 'a foo = lazy []
end
---------------------------------------------------------------------------
The "'a" specified in "empty" is still not the same as in "'a foo". I have
not yet tried to use a functor to bind the function to the correct type,
but I think this should not be necessary. As one can see in the example,
the type of "empty" is correctly inferred in "Foo1" and "Foo2". I do
not understand, why the compiler does not do so in the last case.
Am I overlooking any easy way out? Or is this even a bug?
Best regards,
Markus Mottl
-- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:17 MET