PDA

View Full Version : Matching types?


GnuVince
07-14-2002, 10:27 PM
Is it possible to match types in O'Caml? For example (this does not work, of course):


let print_any t = match t with
int -> print_int
| string -> print_string
| char -> print_char
| _ -> raise "DoH!"
;;



Is there any way to do this? Thanks a lot.

jemfinch
07-15-2002, 02:37 AM
No, there isn't. That's "ad hoc polymorphism" and the ML typesystem has no such support. There's an experimental extension to O'Caml 2.02 called "GCaml" that has such support, though, you might wish to look into it.

Jeremy