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 XAA24215; Mon, 30 Jun 2003 23:36:57 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA24232 for ; Mon, 30 Jun 2003 23:36:55 +0200 (MET DST) Received: from mail.speakeasy.net (mail13.speakeasy.net [216.254.0.213]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5ULasf01065 for ; Mon, 30 Jun 2003 23:36:54 +0200 (MET DST) Received: (qmail 15946 invoked from network); 30 Jun 2003 21:36:52 -0000 Received: from unknown (HELO grace.speakeasy.org) ([216.254.0.2]) (envelope-sender ) by mail13.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 30 Jun 2003 21:36:52 -0000 Date: Mon, 30 Jun 2003 14:36:52 -0700 (PDT) From: brogoff@speakeasy.net To: Chris Hecker cc: "caml-list@inria.fr" Subject: Re: [Caml-list] syntax of private constructors in CVS version In-Reply-To: <4.3.2.7.2.20030630115836.0314dae0@localhost> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; brogoff:01 caml-list:01 hecker:01 crime:99 butter:99 chocolate:99 vending:99 week's:99 recursion:01 bug:01 abstraction:01 nat:01 val:01 prj:99 struct:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 30 Jun 2003, Chris Hecker wrote: > [Excellent rationale for private types snipped.] Indeed. Nice feature. > >In contrast with abstract data types, the private types still maintain > >the elegant pattern matching facility of ML outside the module that > >defines the type. > > So, when do we get views to solve this problem for abstract types? If > pattern matching is so great (which it is) it seems a crime to not allow it > on abstract types (another great feature). To make an american candy joke, > peanut butter and chocolate taste great together! I guess we all know what you're going for when you hit that vending machine! I was going to reply to a message in last week's thread about polytypic programming in which the use of open recursion/fixed points on functions was demonstrated, that there is a "dual" trick at the level of types, the so-called two level types. One place this trick finds some use is in the encoding of views into ML like languages. You can find the trick demonstrated for SML here http://www.cs.princeton.edu/~danwang/drafts/recursion-schemes.pdf but I'm not sure how much using this style costs in efficiency in OCaml. If it costs too much, we'll have to bug Stephen Weeks to implement OCamlton. BTW, it's nice to have views (and all kinds of things) supported directly in the language but these tricks seem workable to me. It seems like OCaml could be a bit nicer than SML here (what a surprise! :), since we could use polymorphic variants for the external interface, as there is no type abstraction there. For example, something like the following for the earliest examples in that paper module type NAT = sig type t type 'a s = [`Zero | `Succ of 'a] val inj : t s -> t val prj : t -> t s end module SimpleNat : NAT = struct type 'a s = [`Zero | `Succ of 'a] (* Look ma, no intermediate constructor for recursive types! *) type t = t s let inj x = x let prj x = x end module FastNat : NAT = struct type 'a s = [`Zero | `Succ of 'a] type t = int let inj = function `Zero -> 0 | `Succ n -> n + 1 let prj = function 0 -> `Zero | n -> `Succ (n - 1) end As a digression, the two level type trick is also used (in OCaml) here http://www.eecs.harvard.edu/~nr/pubs/mania-abstract.html (This is a very appealing paper to me, as the embedded language technique the author describes looks applicable to a few things I'm doing) and here http://homepage.iis.sinica.edu.tw/~trc/padl00.ps and of course in a ton of Haskell/Gofer/Squiggol oriented papers. As another digression, the trick of using open recursive functions and "fixing" them manually with special fps is explained nicely here: http://www.lfcs.informatics.ed.ac.uk/reports/97/ECS-LFCS-97-375/ though the post last week was the first time I saw it used in quite that way. That was quite neat. I wonder how that technique dovetails with two level types? -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners