Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: caml-list@inria.fr (OCAML)
Subject: Problem binding type parameters in modules
Date: Sat, 16 Jan 1999 13:21:35 +0100 (MET)	[thread overview]
Message-ID: <199901161221.NAA00134@miss.wu-wien.ac.at> (raw)

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




             reply	other threads:[~1999-01-18 11:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-16 12:21 Markus Mottl [this message]
1999-01-18 14:59 ` Sylvain BOULM'E
1999-01-18 17:07   ` Problem binding type parameters in modules + subtyping and inheritance Markus Mottl
1999-01-18 19:16     ` Jerome Vouillon
1999-01-18 20:37       ` Markus Mottl
1999-01-19  8:50 ` Problem binding type parameters in modules Hendrik Tews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199901161221.NAA00134@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox