Browse thread
Re: [Caml-list] ocaml and named constants
- Luc Maranget
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Luc Maranget <Luc.Maranget@i...> |
| Subject: | Re: [Caml-list] ocaml and named constants |
>
> 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