From: John Prevost <prevost@maya.com>
To: caml-list@inria.fr
Subject: Interesting behavior of "include"
Date: Fri, 29 Jan 1999 02:20:59 -0500 [thread overview]
Message-ID: <199901290720.CAA28558@zarya.maya.com> (raw)
I started using the "include" directive in signatures recently, then
realized that it's not actually documented anywhere (although it's
quite useful at times.)
I also discovered a little "problem" with it.
module type test =
sig
type t
val a : t
end
module type test2 =
sig
include test
val b : t
end
module type test3 =
sig
include test
val c : t
end
module type testbad =
sig
include test2
include test3 with type t = t
end
(* This would seem to imply that the new type t is the same as the old
when the above expands to:
sig
type t
val a : t
val b : t
type t = t (* just "type t" without the "with" part above. *)
val a : t
val c : t
end
So that a, b, and c would all have the same type.
If you try it without the with, you'll see that they do actually end up
all with the same type, but no matter how hard you try to constrain the
signature using "with", the second "type t" causes t to be abstract.
If you use the with above to try to constrain the second type t
in the signature to be the same as the first (you can't name
which t you mean, since include doesn't let you refer to the
first t as Test2.t), you get an even worse problem:
module type testbad =
sig type t val a : t val b : t type t = t val a : t val c : t end
# module Testbad : testbad with type t = int = struct
# type t = int
# let a = 1
# let b = 1
# let c = 1
# end;;
module Testbad :
sig type t = int val a : t val b : t type t = t val a : t
val c : t end
# Testbad.a;;
- : Testbad.t = Uncaught exception: Stack overflow
This happens with or without the with in the module definition.
Pretty neat, eh? The with definition is allowing you to define a
cyclic type abbreviation. (This is correctly caught in all other
places you can use with as being an unbound type constructor. But
in the include case, it must see that there is, in fact, a type t,
without being able to express in the form of a signature that in
the definition "type t = t", the second t refers to the previously
defined t.
This leaves two problems of course: the first is "include ... with"
needs to check for cyclic type abbreviations, and the second is that
there's no way to constrain includes to be more "merging" than they
are (so that I can define "MONAD_ZERO_PLUS" in terms of "MONAD_ZERO"
and "MONAD_PLUS" instead of in terms of "MONAD", say.)
Of course, I probably shouldn't be using an undocumented feature
in the first place.
*)
jmp
next reply other threads:[~1999-01-29 8:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-01-29 7:20 John Prevost [this message]
1999-01-29 17:08 ` Francisco Valverde Albacete
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=199901290720.CAA28558@zarya.maya.com \
--to=prevost@maya.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