caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Chris King" <colanderman@gmail.com>
To: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: Module type troubles
Date: Tue, 18 Jul 2006 00:31:45 -0400	[thread overview]
Message-ID: <875c7e070607172131m47260672h85e2ed12b054581c@mail.gmail.com> (raw)

(Sorry for the long explaination that follows, it's the most concise
example I can come up with.)

Say I have two polymorphic types with associated constructors:

type 'a foo = { foo: 'a }
let make_foo a = { foo = a }

type 'a bar = { bar: 'a }
let make_bar a = { bar = a }

Using the "combine" function, I am able to define constructors for
compound types:

let combine make_a make_b (a, b) =
    make_a a, make_b b

type 'c foobar = 'a foo * 'b bar constraint 'c = 'a * 'b
let make_foobar c: 'c foobar =
    combine make_foo make_bar c

type 'c foobarfoo = 'a foobar * 'b foo constraint 'c = 'a * 'b
let make_foobarfoo c: 'c foobarfoo =
    combine make_foobar make_foo c


Now I would like to do the same thing with modules:

module Foo = struct
    type 'a t = { foo: 'a }
    let make a = { foo = a }
end

module Bar = struct
    type 'a t = { bar: 'a }
    let make a = { bar = a }
end

module type Combinable = sig
    type 'a t
    val make: 'a -> 'a t
end

module Combine(A: Combinable)(B: Combinable) = struct
    type 'c t = 'a A.t * 'b B.t constraint 'c = 'a * 'b
    let make (a, b) = A.make a, B.make b
end

module FooBar = Combine(Foo)(Bar)
module FooBarFoo = Combine(FooBar)(Foo)

Everything works fine until the last line.  The compiler complains:

Type declarations do not match:
  type 'a t = 'b Foo.t * 'c Bar.t constraint 'a = 'b * 'c
is not included in
  type 'a t

I realize that this is because type 'a FooBar.t cannot exist without
its constraint.  Is there a way to acheive the module structure I
want, save using Obj?

Thanks in advance,
Chris King


             reply	other threads:[~2006-07-18  4:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-18  4:31 Chris King [this message]
     [not found] ` <3C1C2DED-FF8B-4C6C-ABD2-DDFEFF808967@gaillourdet.net>
2006-07-18 13:24   ` [Caml-list] " Chris King

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=875c7e070607172131m47260672h85e2ed12b054581c@mail.gmail.com \
    --to=colanderman@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).