Browse thread
parameterized pattern
[
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: | Martin Jambon <martin1977@l...> |
| Subject: | Re: [Caml-list] parameterized pattern |
On Mon, 6 Nov 2006, Serge Aleynikov wrote:
> Hi,
>
> The section 6.6 of OCaml's manual introduces a notion of "Parenthesized
> patterns".
>
> I couldn't find any examples on how to use this feature, and brute-force
> approach doesn't work:
>
> # match 1.0 with
> (y : float) -> print_float y
> | (s : string) -> print_string s;;
> This pattern matches values of type string
> but is here used to match values of type float
> #
>
> Could anyone point at a suitable resource?
What you wrote is equivalent to:
match ((1.0 : float) : string) with
y -> print_float y
| s -> print_string s
In OCaml, match-with is a test against the structure of a value, not its
type. What you want to do is not currently possible in OCaml.
Martin
--
Martin Jambon, PhD
http://martin.jambon.free.fr