dbuenzli / fmt

OCaml Format pretty-printer combinators
http://erratique.ch/software/fmt
ISC License
71 stars 26 forks source link

Fmt.invalid_arg should type error? #62

Closed yawaramin closed 8 months ago

yawaramin commented 8 months ago

This does not cause a type error:

Fmt.invalid_arg "hello" 1

Is this expected? Fmt.pr shows a type error as I would expect:

# Fmt.pr "hello" 1;;
Error: This expression has type
         ('a -> 'b, Format.formatter, unit, unit, unit, 'a -> 'b)
         CamlinternalFormatBasics.fmt
       but an expression was expected of type
         ('a -> 'b, Format.formatter, unit, unit, unit, unit)
         CamlinternalFormatBasics.fmt
       Type 'a -> 'b is not compatible with type unit
dbuenzli commented 8 months ago

Is this expected?

I guess so. Remember that the type of invalid_arg is string -> 'a = <fun>

dbuenzli commented 8 months ago

If you write

# invalid_arg "hello" 1;;
Warning 20 [ignored-extra-argument]: this argument will not be used by the function.

You get a warning but I guess the format4 type prevents it to trigger in Fmt's case, it's not functional value.

yawaramin commented 8 months ago

Got it, thanks!