I ran into an error similar to this forum post on hubfs, which solved my problem but spawned off some questions about the code in that thread.
let test x = printfn "n" let finall x = x : 'a -> unit let i x = finall test x
Can someone explain to me what line 2 is accomplishing?
I see that the type of finall is
finall: ('a -> unit) -> ('a -> unit)
So its just a function that takes in a function and returns that function.
What would be the reason to do lines 2 and 3?
Can you later define a function body to finall?
it appears that you don’t have to parenthesize the call on the third line, is that a result of line 2?
Yeah, the code on that thread does not make much sense. ‘finall’ is basically the identity function (let id x = x) except that it constrains its argument to be a function-returning-unit rather than some arbitrary value. Basically it doesn’t do anything useful, you could just as easily write
I expect that this snippet maybe came from someone who started with an error message they didn’t understand, and tried to strip it down to a tiny sample repro.
(Regarding function calls, you never need parens to call a let-bound function in F#:
is a call, and function application works in the normal way to support currying, which means
means
which is what is happening on the ‘finall test x’ line.)