caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Carette <carette@mcmaster.ca>
To: skaller <skaller@users.sourceforge.net>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] how to implement generic operators
Date: Mon, 24 Oct 2005 15:27:51 -0400	[thread overview]
Message-ID: <435D35B7.2080905@mcmaster.ca> (raw)
In-Reply-To: <1130131250.28443.79.camel@rosella>


skaller wrote:

>I would clearly need some representation like:
>
>	Assoc of op * term list
>
>and then some kind of fold which works for all different binary op,
>where now 'op' is defined by the user.
>
>So crudely the question is: what is the representation of 'op'
>required so the generic fold can create a wide class of
>generic n-ary operations from binary ones?
>  
>
You really need your operations to be left-associative for that to make 
sense... But in my toy interpreter for a subset of Maple (written in 
Ocaml), I have
type op = term -> term -> term * term
and then in the eval() function for a term, a case
   | Assoc ((f,init), l) -> List.fold_left f init l

f can be created from a term by applying a term-level lambda, so that 
when you ask for

>Note the data for op will be obtained by parsing in the input
>program, so cannot consist of just a fixed list of variants.
>  
>
that can be done too.

>I have a feeling MetaOcaml can do this already.
>  
>
Yes and no.  Yes, it can be done by staging a very finely crafted 
evaluator.  But doing that is very, very difficult given the current 
state-of-the-art [typed PE for typed languages is hard].  Or merely 
difficult if you write everything CPS style.  But it is most definitely 
not something you get right out of the box.

Jacques C.


  parent reply	other threads:[~2005-10-24 19:27 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
2005-10-25  1:56   ` skaller
2005-10-24 19:27 ` Jacques Carette [this message]
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=435D35B7.2080905@mcmaster.ca \
    --to=carette@mcmaster.ca \
    --cc=caml-list@yquem.inria.fr \
    --cc=skaller@users.sourceforge.net \
    /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).