1
votes

As far as I'm aware, F# doesn't handle printfn like it does other functions because of it's type dependence on the string parameter. Could someone explain to me why that prevents me from doing

let printn = printfn "%A"

The error says the type is infered to ('a -> unit) and that I need to add an explicit parameter or a type annotation. Why? I'm perfectly fine with the type it inferred it to. Also, if I add an explicit point, it still has the same type.

1

1 Answers

2
votes

Because printn would be a simple value the way you define it. And values can't be generic in the .NET runtime.

Make the parameter explicit so it is a function:

let printn value = printfn "%A" value

For more information, see the topic Value Restriction on MSDN.