caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Luc Maranget <Luc.Maranget@inria.fr>
To: bpr@best.com (Brian Rogoff)
Cc: Luc.Maranget@inria.fr (Luc Maranget),
	skaller@ozemail.com.au (John Max Skaller),
	caml-list@inria.fr
Subject: Re: [Caml-list] ocaml and named constants
Date: Thu, 31 May 2001 11:22:50 +0200 (MET DST)	[thread overview]
Message-ID: <200105310922.LAA0000007458@beaune.inria.fr> (raw)
In-Reply-To: <Pine.BSF.4.21.0105300940580.19818-100000@shell5.ba.best.com> from "Brian Rogoff" at mai 30, 2001 09:50:13

> 
> On Tue, 29 May 2001, Luc Maranget wrote:
> > > 
> > > 	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.
> 
> I read a paper on an SML extension to handle this named constant problem,
> here at ftp://ftp.research.bell-labs.com/dist/smlnj/papers/92-tr-aitken.ps
> Anyone know why this or some similar approach hasn't caught on? The CamlP4 
> approach isn't too bad, but this seems important enough to be in the core 
> language. 
> 
> This is certainly on my "wish list" for future enhancements, since there
> are so many cases where named constants are useful and the current
> workarounds are a bit ugly. 
> 
> -- Brian
> 
> 
I got the reference and the idea (I think).

These are the so-called ``macros (that work!)''
They give you
  1- Mandatory optimizations (aka inlining)
  2- A different syntax for function and constructor application
     both in patterns.

Stuff for making all that cross module boundaries (allowing data
abstraction and pattern-matching to cohabit) looks a bit
complicated and may not be what you want.

But I have another remark
as far a ``manifest constants'' are the issue, Polymorphic
variants
(http://caml.inria.fr/ocaml/htmlman/manual003.html)
seem to do the job.

After all, provided you do not care much about the actual value of Foo)
you can write :

match x with
| `Foo -> ...
| `Bar -> ...
| _    -> ...

In place of

const Foo = 0
const Bar = 1

match x with
| Foo -> ...
| Bar -> ...
| _   -> ...



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


  reply	other threads:[~2001-05-31  9:22 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
2001-05-30 16:50       ` Brian Rogoff
2001-05-31  9:22         ` Luc Maranget [this message]
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=200105310922.LAA0000007458@beaune.inria.fr \
    --to=luc.maranget@inria.fr \
    --cc=bpr@best.com \
    --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).