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: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] parameterized pattern |
On Monday 06 November 2006 21:15, Serge Aleynikov wrote: > Could anyone point at a suitable resource? I wasn't even aware that you could add type annotations inside a pattern. Your example will not work simply because OCaml's type system will not allow float to unify with string. You need some context where type inference will allow different possibilities, like a tuple containing both a float and a string: # let f = function | (y : float), _ -> print_float y | _, (s : string) -> print_string s;; or a polymorphic variant containing either a float or a string: # let f = function | `F (y : float) -> print_float y | `S (s : string) -> print_string s;; val f : [< `F of float | `S of string ] -> unit = <fun> -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists