[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-07-18 (04:31) |
From: | Chris King <colanderman@g...> |
Subject: | Module type troubles |
(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