From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Mark Wotton <mrak@cs.usyd.edu.au>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] question about modules
Date: Wed, 6 Jun 2001 12:01:28 +0200 [thread overview]
Message-ID: <20010606120127.A30717@miss.wu-wien.ac.at> (raw)
In-Reply-To: <Pine.LNX.4.21.0106061855360.30333-100000@hons.cs.usyd.edu.au>; from mrak@cs.usyd.edu.au on Wed, Jun 06, 2001 at 19:01:23 +1000
On Wed, 06 Jun 2001, Mark Wotton wrote:
> I'm using the translation of Chris Okasaki's code that Markus Mottl has
> provided, and I've got a question about the way modules work. I had
> assumed that it worked in a similar way to lists: ie, i write "int list",
> i'd assumed I'd do something similar with Deques, "int Deque" for
> instance. Obviously this doesn't work: I understand that once I've added
> an element to a Deque, the polymorphic type is fixed, so there's no
> worries about type safety there; however, I had something like this:
I assume you have created a module "Deque" using one of the functors in
chapter 8, e.g.:
module Deque = RealTimeDeque (struct let c = 3 end)
As you can see from the signature restrictions used in the functor head of
"RealTimeDeque", this functor generates modules that match the signature
"DEQUE":
module RealTimeDeque (C : sig val c : int end) : DEQUE
Therefore, we have to look at this signature to see, what options we
have to use deques:
---------------------------------------------------------------------------
module type DEQUE = sig
type 'a queue
val empty : 'a queue
val is_empty : 'a queue -> bool
(* insert, inspect, and remove the front element *)
val cons : 'a -> 'a queue -> 'a queue
val head : 'a queue -> 'a (* raises Empty if queue is empty *)
val tail : 'a queue -> 'a queue (* raises Empty if queue is empty *)
(* insert, inspect, and remove the rear element *)
val snoc : 'a queue -> 'a -> 'a queue
val last : 'a queue -> 'a (* raises Empty if queue is empty *)
val init : 'a queue -> 'a queue (* raises Empty if queue is empty *)
end
---------------------------------------------------------------------------
Obviously, the type used to refer to deques must be:
'a Deque.queue
> type tree = CompTree of tree list * tree list;;
>
> before I realised that I needed deques. It would seem that the translation
> is to
>
> type tree = CompTree of Deque * Deque;;
Thus, you'll have to write:
type tree = CompTree of tree Deque.queue * tree Deque.queue
If it bothers you to write so much, you can also define a type synonym
for deques:
type 'a deque = 'a Deque.queue
and use it instead:
type tree = CompTree of tree deque * tree deque
This is probably the most intuitive version.
Regards,
Markus Mottl
--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-06-06 10:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-30 19:06 [Caml-list] CDK license Brian Rogoff
2001-05-31 1:05 ` rbw3
2001-06-06 7:05 ` Sven LUTHER
2001-06-06 7:42 ` Sven LUTHER
2001-05-31 2:27 ` Jacques Garrigue
2001-05-31 3:11 ` Brian Rogoff
2001-05-31 7:46 ` Fabrice Le Fessant
2001-06-06 7:40 ` Sven LUTHER
2001-06-06 8:36 ` reig
2001-06-06 8:51 ` Sven LUTHER
2001-06-06 9:01 ` [Caml-list] question about modules Mark Wotton
2001-06-06 10:01 ` Markus Mottl [this message]
2001-06-06 13:17 ` Mark Wotton
2001-05-31 22:05 ` [Caml-list] CDK license John Max Skaller
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=20010606120127.A30717@miss.wu-wien.ac.at \
--to=mottl@miss.wu-wien.ac.at \
--cc=caml-list@inria.fr \
--cc=mrak@cs.usyd.edu.au \
/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