English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2003-11-05 (17:51)
From: Dustin Sallings <dustin@s...>
Subject: Re: [Caml-list] function overloading

On Nov 5, 2003, at 2:13, Issac Trotts wrote:

> You can do this:
> type bool_or_int = Bool of bool | Int of int;;
> let print_bool b = print_string (if b then "true" else "false");;
> let print_poly x = match x with
>     Bool b -> print_bool b
>   | Int i -> print_int i;;
> let x = Bool true;;
> print_poly x;;

	This doesn't really solve my problem, I still have to know what the 
type was at some point.  Thanks for the help, though.

	It is good news that your print_bool and mine look identical, though 
(well, you have a space I don't have).  I must be understanding 
something here.  :)

	What I was hoping to do here was print out the termios structure from 
tcgetattr without having to create separate print functions for the 
boolean types, int types, and char types.  It just means I've got to 
pay slightly closer attention.

	Thanks again.

Dustin Sallings

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