Hello, I've been loving F# so far, but I've run into something I'm quite puzzled over. My goal is to bind a function to write to a specific text writer. In the following code, test1 compiles, but both test2 and 3 fail with the same error (on pn "test"): "This expression has type unit but is here used with type string -> unit".
The error changes depending on the first use of pn, i.e., if I do pn with a simple string and no formatters, then it changes and tell me I'm missing an argument. So, somehow the first usage of the pn function is giving it its type, and I can't figure out why.
Would someone please enlighten me as to what's going on here?
#light
open System
let test1 () =
let tw = new IO.StringWriter()
let pn fmt = Printf.twprintfn tw fmt
pn "test %s" "test"
pn "test"
tw.ToString()
let getprint () =
let tw = new IO.StringWriter()
let pn fmt = Printf.twprintfn tw fmt
(tw,pn)
let test2 () =
let tw,pn = getprint ()
pn "test %s" "test"
pn "test"
tw.ToString()
let test3 () =
let tw = new IO.StringWriter()
let pn = Printf.twprintfn tw
pn "test %s" "test"
pn "test"
tw.ToString()