caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Luc Maranget <Luc.Maranget@inria.fr>
To: skaller@ozemail.com.au (John Max Skaller)
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] ocaml and named constants
Date: Tue, 29 May 2001 15:50:05 +0200 (MET DST)	[thread overview]
Message-ID: <200105291350.PAA0000018491@beaune.inria.fr> (raw)
In-Reply-To: <3B12F66C.5F5793F9@ozemail.com.au> from "John Max Skaller" at mai 29, 2001 11:07:56

> 
> Xavier Leroy wrote:
>  
> > > I ask because it seems odd that camlp4 includes
> > > a feature for creating real defined constants that are textually
> > > substituted before compilation begins.
> > 
> > One motivation for this is to be able to put named constants in
> > patterns, e.g.
> > 
> >      match get_next_byte() with
> >        mpg_joint_stereo -> ...
> >      | mpg_78rpm -> ...
> >      | _ -> ...
> > 
> > which cannot be done in plain ML.
> 
> 	Is there any semantic reason why
> one cannot use variables, or even expressions? Apart from
> the obvious syntactic problem.

Not that obvious, I think this would make pattern-matching look
like even more complicated.
It is good to stress on the fact that
in match .. with p ->, p is a pattern
  1. Some value ``whith holes''
  2. Something we programmer and compiler know without any computation.


Just for the sake of avoiding :
if x=mpg_joint_stereo else if x=... else if ...
I would not throw away the simple idea of what a pattern is.

Now the usual Caml answer to such extension of patterns
(the same apply to non-linear patterns such as (x,x))

If you want pattern matching, you can have it !

   match get_next_byte() with
        x when x = mpg_joint_stereo -> ...
      | x when x = mpg_78rpm -> ...
      | _ ->
And, when the mpg_xxx are known constants
some optimization (which does not exist now) could apply, such as
replacing pattern ``x when x=1''  by pattern ``1''.

Hence we need no extension for doing what you wish, we only need more
optimisations.


On the other hand, if we extend pm the way you want
(if I got it right let us assume a backquoting mecanism)
     match get_next_byte() with
        << mpg_joint_stereo >> -> ...
      | << mpg_78rpm >> -> ...
      | _ -> ...
Then we should treat the general case, and 
the semantics can only be
let x = get_next_byte in
if x=mpg_... etc.

The overall benefit of including such a feature is not very clear for me.
Compilation difficulties and programmer errors are, IMHO. on the way.




 -- 
> John (Max) Skaller, mailto:skaller@maxtal.com.au
> 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
> checkout Vyper http://Vyper.sourceforge.net
> download Interscript http://Interscript.sourceforge.net
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr
> 

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  parent reply	other threads:[~2001-05-29 13:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-23 17:06 David Fox
2001-05-28 12:32 ` Xavier Leroy
2001-05-29  1:07   ` John Max Skaller
2001-05-29 12:12     ` Andreas Rossberg
2001-05-29 17:16       ` John Max Skaller
     [not found]         ` <skaller@ozemail.com.au>
2001-05-30  9:46           ` Wolfgang Lux
2001-05-29 13:50     ` Luc Maranget [this message]
2001-05-30 16:50       ` Brian Rogoff
2001-05-31  9:22         ` Luc Maranget
2001-05-31 16:34           ` Brian Rogoff
2001-06-01  4:39             ` David Fox
2001-06-01  1:45           ` John Max Skaller

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=200105291350.PAA0000018491@beaune.inria.fr \
    --to=luc.maranget@inria.fr \
    --cc=caml-list@inria.fr \
    --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;
as well as URLs for NNTP newsgroup(s).