Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] function overloading
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julien Demouth <julien.demouth@f...>
Subject: Re: [Caml-list] function overloading
Dustin Sallings wrote:
> 
>     I swear I found an example demonstrating how to do pattern matching 
> based on the type of an argument, but every pattern matching example I 
> can find now seems to be focused on value and not type.
> 

You've probably read an example of what GCaml offers. GCaml is an 
extension of OCaml allowing some "extensional polymorphic extensions". 
But you have to know that it is based on an old OCaml version. Have a 
look at:

	http://pauillac.inria.fr/~furuse/generics/

>     I'm trying to do something like this:
> 
> let print_poly x = match x with
>     | (x: bool) -> print_bool x
>     | (x: int) ->  print_int x
> ;;
> 
>     Can someone tell me what I'm doing wrong (or perhaps tell me why I 
> shouldn't be doing this at all)?
> 

It cannot work with OCaml because all the expressions in a pattern 
matching have to have the same type. The pattern matching is based on 
variables values and not on their types. It is how the language works.

Julien


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners