Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: brogoff@speakeasy.net
To: John Max Skaller <skaller@ozemail.com.au>
Cc: Mattias Waldau <mattias.waldau@abc.se>,
	"alc@PublicPropertySoftware.com" <alc@PublicPropertySoftware.com>,
	"'caml Mailing List''" <caml-list@inria.fr>
Subject: Re: [Caml-list] Two types of efficiency (Was Efficiency of 'a list)
Date: Sun, 4 May 2003 09:48:38 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0305040900220.23011-100000@grace.speakeasy.net> (raw)
In-Reply-To: <3EB4C2BE.8020407@ozemail.com.au>

On Sun, 4 May 2003, John Max Skaller wrote:
> 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.

As someone else points out, you have the source, you can make polymorphic 
versions of sets/maps/... by coding polymorphic versions of the source and  
instantiating with modules based on polymorphic comparisons.

> 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.

It isn't a syntax problem. I agree that the lack of recursion in the module 
system is a big problem that needs to be fixed (pun intended ;-) but I 
think you (and, more importantly, the FAQ maintainer) should mention that 
there ARE workarounds to these problems. There was a recent discussion 
on this topic here (and in comp.lang.ml, a 2 year long thread!) where you 
can see them. Briefly, the polymorphic sets I just mentioned can be used 
to build simple recursive structures using the parameterization trick at the 
level of types (i.e., a type variable is used to "defer" the instantiation and 
allow you to tie the knot. To build more complex ones, you need to recode 
Set (or whatever functor) to be a functor on an "open" ordered type; the 
comparison function must be parameterized so that you can close the recursion 
later. So, this is the parameterization trick allowed the level of types and 
functions simultaneously. Jean Claude Filliatre showed that one on his message 
on this topic. I haven't tried it with classes, so YMMV. 

The only minor annoyance with that trick is that it requires some textual 
duplication on account of the scope rules for "with type" constraints. This 
is annoying, and I think, syntactic. 

> Result: dont use functors, they're not properly
> supported.

Nonsense. There are places where there can be improvements, but this is as 
whacky as the "don't use lists" assertion. Why are you using classes? Are they 
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++.

Get outta here!

> 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]

Yup, that's annoying. I was nailed by the same problem recently, and I 
used polymorphism to avoid having to write the tags more than once. Something 
like this 

type 'a x' = [`A | `B of 'a]
type x = y x' and y = [y x' | `C of x] 

or something like that, I don't recall. Maybe Jacques will shed some light on 
this restriction. 

Someone else addresses your subtyping issue. 

I have to admit that I have found polymorphic variants puzzling at times, 
but the additional power is amazing and allows you to get at the extensibility 
of OO and beyond. Look up "The Expression Problem" on Google and see if you 
can find a discussion on the defunct Java Genericity mailing list. Or just 
take a look at Jacques Garrigues little paper on code reuse with variants. 
I'm using the same approach to model a different domain than lambda calculus 
evaluators, and while the (algorithmic) complexity of that domain makes 
the evaluator and types a bit more complex, the basic ideas translate easily. 
What a cool language!

-- 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


  parent reply	other threads:[~2003-05-04 16:48 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-02 19:27 [Caml-list] Efficiency of 'a list Eray Ozkural
2003-05-03  5:43 ` Mattias Waldau
2003-05-03  8:16   ` Ville-Pertti Keinonen
2003-05-03 14:12   ` Vitaly Lugovsky
2003-05-03 18:43     ` Mattias Waldau
2003-05-03 20:01       ` Eray Ozkural
2003-05-03 23:17       ` Eray Ozkural
2003-05-04  2:08       ` cashin
2003-05-04  4:08         ` alc
2003-05-04  5:32           ` Ed L Cashin
2003-05-04  6:46           ` [Caml-list] Two types of efficiency (Was Efficiency of 'a list) Mattias Waldau
2003-05-04  7:35             ` John Max Skaller
2003-05-04 11:52               ` Olivier Andrieu
2003-05-05 11:04                 ` John Max Skaller
2003-05-04 16:48               ` brogoff [this message]
2003-05-04  7:43             ` Ville-Pertti Keinonen
2003-05-04 12:50               ` Eray Ozkural
2003-05-04 12:48             ` Eray Ozkural
2003-05-05  7:31             ` Diego Olivier Fernandez Pons
2003-05-05 11:11               ` Mattias Waldau
2003-05-05 13:17                 ` John Max Skaller
2003-05-05 11:49               ` Eray Ozkural
2003-05-05 11:57               ` Yaron M. Minsky
2003-05-05 13:32                 ` John Max Skaller
2003-05-06  2:49                   ` Nicolas Cannasse
2003-05-06 12:30                     ` Diego Olivier Fernandez Pons
2003-05-07  2:05                       ` Nicolas Cannasse
2003-05-05 16:38                 ` Diego Olivier Fernandez Pons
2003-05-05 18:05                   ` Eray Ozkural
2003-05-06 13:28                     ` Diego Olivier Fernandez Pons
2003-05-13 11:35                   ` [Caml-list] Data Structure Libraries (was: Two types of efficiency) Oleg Trott
2003-05-04  7:55           ` [Caml-list] Efficiency of 'a list Ville-Pertti Keinonen
2003-05-04 10:56             ` Neel Krishnaswami
2003-05-04 12:56               ` Eray Ozkural
2003-05-04 13:35                 ` Falk Hueffner
2003-05-04 12:38           ` Eray Ozkural
2003-05-04  8:07         ` Ville-Pertti Keinonen
2003-05-04 15:54           ` Ed L Cashin
2003-05-05 23:52           ` Garry Hodgson
2003-05-03 20:03   ` Eray Ozkural
2003-05-03 21:13 ` Lauri Alanko
2003-05-03 22:03   ` Eray Ozkural

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=Pine.LNX.4.44.0305040900220.23011-100000@grace.speakeasy.net \
    --to=brogoff@speakeasy.net \
    --cc=alc@PublicPropertySoftware.com \
    --cc=caml-list@inria.fr \
    --cc=mattias.waldau@abc.se \
    --cc=skaller@ozemail.com.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