caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] printf arguments
@ 2002-06-20 18:12 Henri Dubois-Ferriere
  2002-06-21 12:11 ` Pierre Weis
  0 siblings, 1 reply; 2+ messages in thread
From: Henri Dubois-Ferriere @ 2002-06-20 18:12 UTC (permalink / raw)
  To: caml-list

In trying to write a wrapper around printf for debug message logging, 
(a la syslog), I am coming across the following problem:

# let myprintf fmt = if (true) then Printf.fprintf stdout fmt;;
val myprintf : (unit, out_channel, unit) format -> unit = <fun>

# Printf.fprintf;;
- : out_channel -> ('a, out_channel, unit) format -> 'a = <fun>


so the myprintf function above does not have the same type as the original 
fprintf. Note that removing the if clause returns us to the proper type:

# let myprintf fmt = Printf.fprintf stdout fmt;;
val myprintf : ('a, out_channel, unit) format -> 'a = <fun>



Any clue why this is so, and how to get around it?

Thanks,

Henri

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] printf arguments
  2002-06-20 18:12 [Caml-list] printf arguments Henri Dubois-Ferriere
@ 2002-06-21 12:11 ` Pierre Weis
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 2002-06-21 12:11 UTC (permalink / raw)
  To: henri.dubois-ferriere; +Cc: caml-list

> In trying to write a wrapper around printf for debug message logging, 
> (a la syslog), I am coming across the following problem:
> 
> # let myprintf fmt = if (true) then Printf.fprintf stdout fmt;;
> val myprintf : (unit, out_channel, unit) format -> unit = <fun>

If cond then expr == if cond then expr else ()

[...]
> so the myprintf function above does not have the same type as the original 
> fprintf. Note that removing the if clause returns us to the proper type:
> 
> # let myprintf fmt = Printf.fprintf stdout fmt;;
> val myprintf : ('a, out_channel, unit) format -> 'a = <fun>

If you want to preserve the original typing of printf, you must
imperatively use a tail call to printf (due to the typing discipline
of string format).

Regards,

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-06-21 12:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-20 18:12 [Caml-list] printf arguments Henri Dubois-Ferriere
2002-06-21 12:11 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).