caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: Luc Maranget <luc.maranget@inria.fr>
Cc: sejourne_kevin <sejourne_kevin@yahoo.fr>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Request for complete pattern matching
Date: Wed, 23 Nov 2005 21:56:37 +0100	[thread overview]
Message-ID: <4384D785.5010106@univ-savoie.fr> (raw)
In-Reply-To: <20051123183134.GB6446@yquem.inria.fr>

[-- Attachment #1: Type: text/plain, Size: 2640 bytes --]


> 
> Well, I understand better and (as you may have guessed yourself!) I do
> not incline to adopt the idea.
> 
> However provided you have some 'break' construct to transfert control to
> next matching, you can perhaps compile your construct by syntactic 
> transformation.
> 
> 
> My idea is to transform your patterns into
> normal ones, replacing p <= e1 e2 ... en by fresh variables (say v)
> and then to match 'v e1 ... en' against p.
> 
> Here you have :
> 
> match e with
> | (v1, g) -> (match v1 0 with 0 -> g |_ -> break)
> | (f, v2) -> (match v2 0 with 0 -> f |_ -> break)
> | f, g -> fun x -> f x + g x
> 
> At a little additional cost in complexity,
> you can replace 'break' (which does not exists) by exceptions as follows
> 
> let x = e in
> try (match x with
>   | (v1, g) -> (match v1 0 with 0 -> g |_ -> raise Exit)
>   | _ -> raise Exit)
> with Exit ->
> try (match x with
>   | (f, v2) -> (match v2 0 with 0 -> f |_ -> raise Exit)
>   | _ -> raise Exit)
> with Exit ->
> (match x with  f, g -> fun x -> f x + g x)
> 
> 
> I am not familiar enough with Camlp4, but I have the feeling
> that some purely syntactic compilation of your construct is doable.
> Since, only from the presence of <=,
> can you introduce the extra matchings and try .. with Exit) 
> I am not saying it is easy, just that it looks feasible.
> 
> Typing and warnings are yet another issue!
> 

I agree that your translation works (I should try). I  am just wondering
about the cost (compared to a reasonable implementation inside the
compiler) ?

That would probably be not so dramatic ... except I should not transform
pattern matching that do not use the new extension ... the camlp4 code
will probably tripple what I have.

Moreover, I think I may use camlp4 for bindlib-3.0, because this really
is an extension of the language and not a library ... however I do not
think camlp4 extensions are a good thing in general, because it breaks
readability of code.

So for my extension of pattern matching with function application, I
think, I prefer to wait an adoption of a similar feature rather than
doing it myself. bindlib-3.0 will be ok without this extention of the
pattern matching.

One of the reason for my post, is that I think pattern matching should
be complete (one of the reason, is because then you can interpret the
semantics of the language by the interaction of a constructor and a
destructor ... this has something to do with a lot of reasearch work in
computational interpretation of classical logic ... and trying to move
the language in this direction looks fun ..., for instance have a look
at Herbelin's work)

> 
> -- Luc

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 894 bytes --]

  parent reply	other threads:[~2005-11-23 20:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-22 22:43 Christophe Raffalli
2005-11-23  5:54 ` [Caml-list] " Luc Maranget
2005-11-23 14:37   ` Christophe Raffalli
2005-11-23 10:06 ` Michal Moskal
2005-11-23 15:26   ` Christophe Raffalli
     [not found] ` <43842069.3070700@yahoo.fr>
2005-11-23 14:47   ` Christophe Raffalli
2005-11-23 18:31     ` Luc Maranget
2005-11-23 20:56       ` Martin Jambon
2005-11-23 21:30         ` skaller
2005-11-23 22:25           ` Martin Jambon
2005-11-24  9:29         ` Luc Maranget
2005-11-25 23:01           ` Martin Jambon
2005-11-23 20:56       ` Christophe Raffalli [this message]
2005-11-24  9:41         ` Luc Maranget

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=4384D785.5010106@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=caml-list@inria.fr \
    --cc=luc.maranget@inria.fr \
    --cc=sejourne_kevin@yahoo.fr \
    /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).