[nem-en] Re: match on specific parameter
Kamil Skalski
kamil.skalski at gmail.com
Sun Jan 29 18:54:58 CET 2006
2006/1/29, Michal Moskal <michal.moskal at gmail.com>:
> Some more thoughts:
>
> On 1/29/06, Michal Moskal <michal.moskal at gmail.com> wrote:
> > But I personally don't find it very readable. I would like something
> > like:
> >
> > def rev (acc, match lst)
> > | x :: xs => rev (x :: acc, xs)
> > | [] => acc
I like this one. It should be allowed on any subset of parameters:
def rev (match lst, acc)
| x :: xs => rev (x :: acc, xs)
| [] => acc
Then the standard
def foo (x, y) {
| (1, 2) => ...
}
would be a shortcut for
def foo (match x, match y) {
| (1, 2) => ...
}
The problem of single / multiple matching bothers be for a long time.
Ocaml allows to
"implicitly" match on one or more LAST parameters, maybe this is not
as bad design as I thought some time ago.
> >
> > or maybe "def rev (acc, match)". I'm not sure about the syntax.
>
> Maybe we could use default parameters as a hint:
>
> def rev (lst, acc = [])
> | x :: xs => ...
It is not even clear what it means... Is it equivalent to:
def rev (lst, acc)
(x :: xs, []) =>
or to the original example
def rev (lst, acc)
match (lst)
| x :: xs =>
?
> >
> > On a related note, d proposed on IRC, that we could transform:
> >
> > foo () : ...
> > | ...
> >
> > inside classes and variants to:
> >
> > foo () : ...
> > match (this)
> > | ...
> >
> > which I think also makes sense.
Nice, but I think it is a little bit "unclean". That is, 'this' comes
there from nowhere. Also, would you ommit this rule if there is some
parameter?
>
> Maybe it should be also possible to say:
>
> foo (match this, some_flag : bool)
> | ...
>
I guess
foo (some_flag : bool)
match (this)
|
is cleaner.
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list