0
votes

I am trying to have the following signature for a function compute:

val compute = fn: string -> string -> string

I know how to use higher order functions by introducing a let in the function, however the result might be changed into

val compute = fn: string -> (fn: string -> string) -> string.

I need the signature to be correct. Can anymore explain this to me and it would be much appreciated if you can give one or two examples.

1
What is the definition of compute that is giving you the incorrect function signature?lea
The question actually has nothing to do with functionality of compute. I figured it out eventually. The difference between the first one and the second one is the first signature allow me to pass two strings for the function one by one, having one of the function as a variable : ) The example will be compute "test1" "test2". Thanks still!angerhang
@angerhang, can you share your answer? You can answer your own questions: blog.stackoverflow.com/2011/07/…Jon

1 Answers

1
votes

Even though

fn: string -> string -> string

and

fn: string -> (fn: string -> string) -> string

both take two strings as input and have one string as output. The operation is different inside the function. The first one, take one string as input, and perhaps have a local function that also take the second string as have one string as output. (two strings in the parameters in the local function)

the second one will have a higher order function which one string as input for the let in function.