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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Basile Starynkevitch <basile.starynkevitch@i...>
Subject: Re: [Caml-list] Printf question
On Sat, Sep 27, 2003 at 08:23:25AM +0100, Richard Jones wrote:
> On Sat, Sep 27, 2003 at 02:11:14AM +0200, Olivier Andrieu wrote:
> > You could use the %a format. [...]
> 
> I guess the problem with this is that I lose any type safety,
> which is the whole point of doing things this way.
> 

I don't think that %a in formats lose type safety (provided that the passed
function has the correct type).

# let pr= function 0->"zero" | 1->"one" | n -> string_of_int n;;
val pr : int -> string = <fun>
# let myprint n = Printf.sprintf "n=%a" (fun () n->pr n) n;;
val myprint : int -> string = <fun>
# myprint 1;;
- : string = "n=one"

-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359
http://cristal.inria.fr/~starynke --- all opinions are only mine 

-------------------
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