Version française
Home     About     Download     Resources     Contact us    
Browse thread
Problem binding type parameters in modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <mottl@m...>
Subject: Problem binding type parameters in modules
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