caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Martin Chabr <martin_chabr@yahoo.de>
Cc: caml-list@yquem.inria.fr
Subject: Re: Ant:  [Caml-list] how to implement generic operators
Date: Tue, 25 Oct 2005 11:09:20 +1000	[thread overview]
Message-ID: <1130202560.18325.21.camel@rosella> (raw)
In-Reply-To: <20051024182654.24834.qmail@web26808.mail.ukl.yahoo.com>

On Mon, 2005-10-24 at 20:26 +0200, Martin Chabr wrote:

> I was surprised at first when I found out how OCaml
> restricts lists.

> Now I got used to it and appreciate the clarity: types
> in mixed expressions must always be converted to be
> compatible with each other. No automatic conversion
> where you wonder what will happen.

> C# had collections of mixed types as well in the 1.x
> version. Now, in the version 2.0 they have generics
> and strong type checking and everybody seems to like
> it, not having to do any type detection and casting.

The idea is to provide 'manifest' heterogeneity
like this:

iter print (1,2.0,"Hello");

which of course is just sugar for

print 1; print 2.0; print "Hello";

This will work in Felix because it supports overloading.
There is no loss of type safety, since each of the 
3 generated terms is independently type checked.

Internally, the Ocaml representation would be something like

Iter (print, [1;2.0;"Hello"])

and the reduction rule would be something like:

function 
| Iter (op, elts) -> fold_left 
  (fun (result, elt) -> seq (result, op elt)) nop elts

So basically this operation is just sugar which takes
advantage of 'ad hoc polymorphism' aka overloading to
allow the user to get 'free' nary operators.

Note that the second argument to 'iter', 
namely (1,2.0, "hello"), is a *tuple*. It is therefore
heterogenous automatically, but of fixed length.

In Ocaml the *representation* is a list of terms, all of
the same type, namely 'expression'.

What I wrote above using Iter variant will work just fine.
The problem is, I also need Compose, Ravel, ... and many MANY
others. There are far too many to encode all of them in the
compiler: a reasonable fixed subset will remain both incomplete
and a lot of work to encode.

So instead of encoding them all in the compiler, I want
to encode them in the standard library, parse them,
and write an interpreter in Ocaml to 'execute' the 
parsed encodings.

See Jacques Carette post and my response for more.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2005-10-25  1:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-24  5:20 skaller
2005-10-24 18:26 ` Ant: [Caml-list] " Martin Chabr
2005-10-25  1:09   ` skaller [this message]
2005-10-25  1:56   ` skaller
2005-10-24 19:27 ` Jacques Carette
2005-10-25  1:43   ` skaller
2005-10-25 15:52     ` Jacques Carette

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=1130202560.18325.21.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@yquem.inria.fr \
    --cc=martin_chabr@yahoo.de \
    /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;
as well as URLs for NNTP newsgroup(s).