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 JAA29808; Sun, 4 May 2003 09:35:44 +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 JAA29915 for ; Sun, 4 May 2003 09:35:43 +0200 (MET DST) Received: from mail3.tpgi.com.au (mail.tpgi.com.au [203.12.160.59]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h447ZfH08118 for ; Sun, 4 May 2003 09:35:42 +0200 (MET DST) Received: from ozemail.com.au (syd-ts14-2600-122.tpgi.com.au [203.213.82.122]) (authenticated (0 bits)) by mail3.tpgi.com.au (8.11.6/8.11.6) with ESMTP id h447ZQM14502; Sun, 4 May 2003 17:35:27 +1000 Message-ID: <3EB4C2BE.8020407@ozemail.com.au> Date: Sun, 04 May 2003 17:35:26 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: Mattias Waldau CC: alc@PublicPropertySoftware.com, "'caml Mailing List''" Subject: Re: [Caml-list] Two types of efficiency (Was Efficiency of 'a list) References: <041d01c31208$f02327e0$0200a8c0@gateway> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ozemail:01 caml-list:01 mattias:01 waldau:01 stringset:01 struct:01 beginners:01 recursion:01 functor:01 functors:01 subtyping:01 textual:01 covariance:01 disallows:01 expressivity:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Mattias Waldau wrote: > > Languages like PHP have more advanced built-in datastructures with > language syntax to support them. In Ocaml, we can create the same > program, however, there is no syntax support, and we have to add > declarations like > > module StringSet = Set.Make(struct > type t = string > let compare = compare > end) ;; > > It would be nice if the typechecker could deduce the type of the set and > add the above declaration automatically to the program. That would make > it easier for beginners to use the advanced datastructures of Ocaml. The problem is worse than that. There are places you need such an animal but CANNOT have it. This occurs when there is type recursion involved and the lack of orthogonality in Ocaml syntax prevents you actually declaring the functor instance at the point you need it. This occurs in a class where for example you have a set of references to that class passed to one of the methods of the class: the functor instantiation requires the class type to be complete, but it cannot be completed until the functor is instantiated. [You need to declare the functor inside the class but before the object] Result: dont use functors, they're not properly supported. I found this really annoying. It applies in other parts of the language too, for example polymorphic variants. Here again, the very feature functional languages are supposed to understand best -- recursion -- is actually handled better in C++. I need variants whose arguments include the variant type, and I can't have them together with subtyping. Yet for someone representing a programming language recursion is natural. type x = [`A | `B of y] and y = [x | `C of x] There is no problem doing this with textual substitution: type x = [`A | `B of y] and y = [`A | `B of y | `C of x] Similarly, subtyping of polymorphic variants is invariant in the arguments, when covariance is sound and more useful. This is a real pain for me, since it destroys the main use I hoped to obtain for polymorphic variants: type x = [`A | `B of x] type y = [`A | `B of y | `C] x *is* a subtype of y, but the type system disallows it, failing to recognise that every `B x of type x is also a `B y of y. Typically I have say a term for an expression and I want to eliminate some cases by say a term reduction, but I can't restrict the resultant type as desired because there's no way to 'narrow' the type recursion. So here are two cases where (a) syntax and (b) loss of semantic expressivity reduce the utility of the language. Luckily, the ocaml team is working on such things: local modules, for example, help considerably. Its somewhat unfortunate that the syntactic constraints often make a clean solution difficult, for example: type x = ... and class .. woops: you cant inter-recurse classes and types. You have to use a trick: make the class parametric, then inter-recurse the type x and the instantiation passing x as the argument: ugg. The restriction appears to be entirely a matter of syntax: to distinguish classes and types you'd need the 'type' and 'class' keyword on each conjunct which breaks: type x = .. and y = .. It would appear that the diverse nature of things to be declared indicates this syntax, along with let x = .. and y = .. is in fact wrong: better to have required: let type x = .. and val y = .. and class z = .. As we see in C++, historically sound syntax soon breaks with language extensions :( -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- 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