Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type of Printf.ifprintf and ikfprintf could be more general #6904

Closed
vicuna opened this issue Jun 16, 2015 · 3 comments
Closed

Type of Printf.ifprintf and ikfprintf could be more general #6904

vicuna opened this issue Jun 16, 2015 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Jun 16, 2015

Original bug ID: 6904
Reporter: @zoggy
Status: closed (set by @damiendoligez on 2016-04-15T16:46:02Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.1
Category: standard library

Bug description

Hello,

ifprintf and ikfprintf appears in Printf interface as:

val ifprintf : 'a -> ('b, 'a, unit) format -> 'b
val ikfprintf : (out_channel -> 'a) -> out_channel ->
('b, out_channel, unit, 'a) format4 -> 'b

But the types inferred from their implementation are more general:

cat > p.ml

open CamlinternalFormatBasics;;
open CamlinternalFormat;;
let ikfprintf k oc (Format (fmt, _)) =
make_printf (fun oc _ -> k oc) oc End_of_acc fmt
let ifprintf oc fmt = ikfprintf ignore oc fmt
^D

ocamlc -i p.ml

val ikfprintf :
('a -> 'b) ->
'a -> ('c, 'a, 'd, 'd, 'd, 'b) CamlinternalFormatBasics.format6 -> 'c
val ifprintf :
'a -> ('b, 'a, 'c, 'c, 'c, unit) CamlinternalFormatBasics.format6 -> 'b

Is there a reason to constraint these types ? ifprintf would be more useful with a more general type, for example in codes like the following:

let p fmt = Printf.ksprintf prerr_endline fmt ;;
let f b p fmt = if b then p fmt else ifprintf () fmt
let log fmt = f true p fmt

With the current types for i* functions, the code above has a type error on the third format argument.

@vicuna
Copy link
Author

vicuna commented Jun 16, 2015

Comment author: @gasche

I see nothing wrong with relaxing those signatures, but the one proposed in the .mli must be made more readable than this inference result, by:

  • using format4 instead of format6
  • using ('a, 'b, 'c, 'd) or ('a, 'b, 'c, 'e) for the parameter names of the format4 argument.

Would you like to propose a patch?

@vicuna
Copy link
Author

vicuna commented Jun 16, 2015

Comment author: @zoggy

Sure: #201

@vicuna
Copy link
Author

vicuna commented Apr 15, 2016

Comment author: @damiendoligez

Fixed by #201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant