Browse thread
[Caml-list] variant with tuple arg in pattern match?
-
Chris Hecker
-
Patrick M Doane
-
Chris Hecker
- Daniel de Rauglaudre
- Patrick M Doane
- Xavier Leroy
-
Chris Hecker
- Alain Frisch
-
Patrick M Doane
[
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: | Daniel de Rauglaudre <daniel.de_rauglaudre@i...> |
| Subject: | Re: [Caml-list] variant with tuple arg in pattern match? |
Hi,
My opinion is that the confusion comes from the syntax. In my revised syntax
by Camlp4, I propose to represent constructors with several parameters with
currification syntax. You can write:
type t1 = [ Foo of int and int ] to specify two parameters
type t2 = [ Bar of (int * int) ] to specify one parameter, a tuple
And you (must) write:
Foo 3 5
Bar (3, 5)
The case:
Foo 3
answers:
The constructor Foo expects 2 argument(s),
but is here applied to 1 argument(s)
which is normal.
Idem for the case:
match x with [ Foo y -> y ]
To get the couple, you have to write:
match x with [ Foo y z -> (y, z) ]
This is logical. With this syntax, no possible confusion. You would
even not have asked the question.
It is not a question of semantics, but a question of *syntax*.
--
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr