|
|
|
|
|
by trealira
761 days ago
|
|
> Isn't Int -> String -> String a shorthand for Int -> (String -> String)? Yes. Though I find it more convenient think of it as a function with multiple arguments and not a function that returns another function. > Thus I would have assumed the first argument to the result of sprintf "%s %d" would be an integer, then a string and the final result would be a string. Why assume that? (Not rhetorical.) Wouldn't that be like if in C, you had to write the arguments in reverse order of the format string, like this? printf("%s %d!\n", 5, "hi");
|
|
> Wouldn't that be like if in C, you had to write the arguments in reverse order of the format string, like this?
Exactly and that's not what we want
Let's go through this step by step:
sprintf "%s %d" returns a function, taking a string and returning a function taking an integer and returning a string, right?
sprintf "%s %d" "hello" returns a function taking an integer, returning a string, right?
sprintf "%s %d" "hello" 42 returns a string, right?
Thus my intuition of the return type of sprintf "%s %d" would be string -> (int -> string) not int -> (string -> string)