| Anonymous | Login | Signup for a new account | 2013-05-22 07:00 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | |||||||
| 0005576 | OCaml | OCaml standard library | public | 2012-04-06 12:53 | 2012-04-11 20:28 | |||||||
| Reporter | lealanko | |||||||||||
| Assigned To | weis | |||||||||||
| Priority | normal | Severity | feature | Reproducibility | always | |||||||
| Status | resolved | Resolution | fixed | |||||||||
| Platform | OS | OS Version | ||||||||||
| Product Version | 3.12.1 | |||||||||||
| Target Version | Fixed in Version | |||||||||||
| Summary | 0005576: Missing continuation-passing no-op formatter in Printf | |||||||||||
| Description | Although there is a continuation-passing no-op formatting function available as Format.ikfprintf, a corresponding function in Printf seems to be missing. Here is an implementation: val kiprintf : (unit -> 'a) -> ('b, unit, unit, 'a) format4 -> 'b let kiprintf k = kapr (fun _ _ -> Obj.magic (k ())) (Also, I think that the name Printf.ifprintf should be deprecated and renamed to Printf.iprintf since it does not take an out_channel as a parameter.) | |||||||||||
| Tags | No tags attached. | |||||||||||
| Attached Files | ||||||||||||
Notes |
|
|
(0007310) doligez (manager) 2012-04-10 16:26 |
What is the use-case for this function? You can get a good approximation with: let kiprintf k fmt = ksprintf (fun _ -> k ()) fmt;; It allocates a useless string, but for debugging purposes that's not a big deal. |
|
(0007332) weis (developer) 2012-04-11 19:40 |
Granted: ikfprintf was not implemented in module Printf. As in Format, a partial applicatio of ikfprintf would be useful to implement ifprintf, and could be useful to the user as well. Implemented in the current sources for version 4.0 of the compiler. |
|
(0007333) weis (developer) 2012-04-11 19:46 |
Printf.ifprintf is not at all deprecated. It is the corresponding ``ignoring function'' for fprintf. In fact, it can take an out_channel as parameter (otherwise it would not be compatible with fprintf). You may have been fooled by the polymorphic type scheme of ifprintf: indeed the type-checker detected that ifprintf is ignoring its channel argument and then assign a polymorphic 'a to this argument; but indeed this 'a could be instanciated to out_channel. Indeed, typical use-case for ifprintf is let debug fmt = if <some condition> then fprintf stderr fmt else ifprintf stderr fmt ;; You may read the i in ifprintf as (i)gnoring or (i)f ... |
|
(0007334) weis (developer) 2012-04-11 19:54 |
Damien gave you a short (and free of Obj.magic) definition for your kiprintf function. Then he asked for a typical use-case. I would ask for an english explanation of what this function is supposed to do ? I feel it strange to get as argument a continuation with type unit -> 'a. If indeed you where thinking of a Printf equivalent of Format.ikfprintf, then the typical use-case is the same as for ifprintf, adding continuation in the picture: let kdebug k fmt = if <some condition> then kfprintf k stderr fmt else ikfprintf k stderr fmt ;; |
|
(0007335) weis (developer) 2012-04-11 20:28 |
Printf.ifprintf defined as partial evaluation of ikfprintf. |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2012-04-06 12:53 | lealanko | New Issue | |
| 2012-04-10 16:26 | doligez | Note Added: 0007310 | |
| 2012-04-10 16:26 | doligez | Status | new => feedback |
| 2012-04-11 19:40 | weis | Note Added: 0007332 | |
| 2012-04-11 19:46 | weis | Note Added: 0007333 | |
| 2012-04-11 19:54 | weis | Note Added: 0007334 | |
| 2012-04-11 19:55 | weis | Assigned To | => weis |
| 2012-04-11 19:55 | weis | Status | feedback => assigned |
| 2012-04-11 20:28 | weis | Note Added: 0007335 | |
| 2012-04-11 20:28 | weis | Status | assigned => resolved |
| 2012-04-11 20:28 | weis | Resolution | open => fixed |
| Copyright © 2000 - 2011 MantisBT Group |