If I define a simple function:
let myConcat a b =
a + "+" + b
Then given the claim that functions are first-class values in F#, I'd expect to be able to use myConcat
like this:
let result = myConcat "a" (fun () -> "b")
Rather than yielding a string "a+b", it gives me the following error:
error FS0002: This function takes too many arguments, or is used in a context where a function is not expected
Hopefully, I'm simply getting the syntax wrong, but it looks to me like functions cannot truly be used as values in F#. Can anyone explain what's going on here?
EDIT To further clarify what I'm asking, I could have the equivalent C# code:
public string myConcat(string a, string b) { return a + "+" + b; }
If I however wanted to pass a "call later function" in param b, I'd have to make it:
public string myConcat(string a, Action<string> b) { return a + "+" + b(); }
Or I could call it thus:
Func<string> b = () => "b";
var result = myConcat("a", b());
C# doesn't (to my knowledge) make the claim that functions are first-class values. F# does make that claim. So what's the difference when I can't treat a unit -> string function as a "lazy evaluated" string value?