From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA29518; Wed, 6 Jun 2001 12:01:36 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA29494 for ; Wed, 6 Jun 2001 12:01:35 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f56A1YL06091 for ; Wed, 6 Jun 2001 12:01:35 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id MAA13879; Wed, 6 Jun 2001 12:01:28 +0200 (MET DST) Date: Wed, 6 Jun 2001 12:01:28 +0200 From: Markus Mottl To: Mark Wotton Cc: caml-list@inria.fr Subject: Re: [Caml-list] question about modules Message-ID: <20010606120127.A30717@miss.wu-wien.ac.at> References: <20010606105106.A7120@lambda.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from mrak@cs.usyd.edu.au on Wed, Jun 06, 2001 at 19:01:23 +1000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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