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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <pierre.weis@i...>
Subject: Re: [Caml-list] printf hook
> I just found something quite funny :
> 
> let print x =
>     printf "BEGIN";
>     printf x;
>     flush stdout
> 
> print "test";;
> print "%d" 10; (** TOO MUCH ARGS **)

This is normal, isn't it ?

> ============
> 
> let print x =
>     printf "BEGIN";
>     let r = printf x in
>     flush stdout;
>     r
> 
> print "test";
> print "%d" 10; (** WORKING **)

This is also perfectly regular: your code

let print x =
  printf "BEGIN";
  let r = printf x in
  flush stdout;
  r

is functionally equivalent to

let print x =
  let r = printf x in
  r

which is again functionally equivalent to

let print x = printf x

which is again equivalent to

let print = printf

The type checker gives an hint on that fact, since print is reported
having the same type as printf:

        Objective Caml version 3.04+15 (2002-06-18)

#open Printf;;
# let print x =
  printf "BEGIN";
  let r = printf x in
  flush stdout;
  r;;
val print : ('a, out_channel, unit) format -> 'a = <fun>
# printf;;
- : ('a, out_channel, unit) format -> 'a = <fun>

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


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