|
List Info
Thread: "ocaml_beginners"::[] confusion in nexted module types
|
|
| "ocaml_beginners"::[]
confusion in nexted module types |

|
2006-12-13 22:05:17 |
|
Hi,
I am confused as to why the following code does not compile:
module type A =
sig
type a
module type B = sig type b end;;
val f : B.b -> a
end;;
>> "Unbound type constructor B.b"
Could someone explain this to me?
Thanks,
-Nick
[Non-text portions of this message have been removed]
__._,_.___
.
__,_._,___
|
| "ocaml_beginners"::[]
confusion in nexted module types |

|
2006-12-13 22:23:18 |
|
On Wed, 13 Dec 2006, Nick Kidd wrote:
> Hi,
> I am confused as to why the following code does not compile:
>
> module type A =
> sig
>
> type a
>
> module type B = sig type b end;;
>
> val f : B.b -> a
>
> end;;
>
>>> "Unbound type constructor B.b"
>
> Could someone explain this to me?
This is because a module type is not the same thing as a module signature,
and what you need is a module signature inside the declaration of module
type A.
You can do this in one of two ways:
module type A =
sig
type a
module B : sig type b end
val f : B.b -> a
end;;
-or-
module type B_Type =
sig
type b
end;;
module type A =
sig
type a
module B : B_Type
val f : B.b -> a
end;;
Hope that helps. Let us know if you still have questions.
William D. Neumann
---
"There's just so many extra children, we could just feed the
children to these tigers. We don't need them, we're not doing
anything with them.
Tigers are noble and sleek; children are loud and messy."
-- Neko Case
Life is unfair. Kill yourself or get over it.
-- Black Box Recorder
__._,_.___
.
__,_._,___
|
| "ocaml_beginners"::[]
confusion in nexted module types |

|
2006-12-13 22:24:00 |
|
On Wed, 13 Dec 2006, Nick Kidd wrote:
> Hi,
> I am confused as to why the following code does not compile:
>
> module type A =
> sig
>
> type a
>
> module type B = sig type b end;;
>
> val f : B.b -> a
>
> end;;
>
> >> "Unbound type constructor B.b"
>
> Could someone explain this to me?
Yes: B is a module type, not a module. Therefore, you cannot ask for B.b.
Maybe you mean this:
module type A_type =
sig
type a
module type B_type = sig type b end
module B : B_type
val f : B.b -> a
end
I like to append "_type" after the name of module types, otherwise it's
too confusing.
Martin
--
Martin Jambon, PhD
http://martin.jambon.free.fr
__._,_.___
.
__,_._,___
|
| "ocaml_beginners"::[]
confusion in nexted module types |

|
2006-12-13 22:30:55 |
|
On Wed, 13 Dec 2006, William D. Neumann wrote:
> This is because a module type is not the same thing as a module signature,
> and what you need is a module signature inside the declaration of module
> type A.
Bleah. I wrote this poorly. It should really say that module type
declarations are not the same as module signatures.
And in addition to my two earlier examples, you can include the type
declaration inside of the declaration for A as well.
module type A =
sig
type a
module type B_Type = sig type b end
module B : B_Type
val f : B.b -> a
end;;
Of course, if you do it this way, the module type B_Type remains local to
modules of type A, and not open to the rest of teh world (which you may
want).
William D. Neumann
---
"There's just so many extra children, we could just feed the
children to these tigers. We don't need them, we're not doing
anything with them.
Tigers are noble and sleek; children are loud and messy."
-- Neko Case
Life is unfair. Kill yourself or get over it.
-- Black Box Recorder
__._,_.___
.
__,_._,___
|
| "ocaml_beginners"::[]
confusion in nexted module types |

|
2006-12-13 22:39:15 |
|
On Wed, 13 Dec 2006, William D. Neumann wrote:
> On Wed, 13 Dec 2006, Nick Kidd wrote:
>
> > Hi,
> > I am confused as to why the following code does not compile:
> >
> > module type A =
> > sig
> >
> > type a
> >
> > module type B = sig type b end;;
> >
> > val f : B.b -> a
> >
> > end;;
> >
> >>> "Unbound type constructor B.b"
> >
> > Could someone explain this to me?
>
> This is because a module type is not the same thing as a module signature,
> and what you need is a module signature inside the declaration of module
> type A.
Mmmmm, I believe you mean "the piece of module signature that corresponds
to a module definition is not the same as the definition of a module
signature".
The former is:
module X : sig ... end
or:
module X : X_type
while the latter is:
module type X_type = sig ... end
Martin
--
Martin Jambon, PhD
http://martin.jambon.free.fr
__._,_.___
.
__,_._,___
|
[1-5]
|
|