3 ms·
> > program3 fails because runFunction can only run first-order functions and runFunction is a second-order function – a function that takes a first-order funct
by kmill 9y ago
> > program3 fails because runFunction can only run first-order functions and runFunction is a second-order function – a function that takes a first-order function as a parameter.
> Here I had no idea that JavaScript implicitly typed `runFunction` that way. That's cool.
In case it's not clear, it's just that it eventually ends up with a run time error (the talk about runFunction being a second-order function is just an explanation for why you should expect it to end up with a run time error). The evaluation is
program3()
== runFunction(runFunction)
== runFunction(1)
== 1(1)
== Error: func (with value 1) is not a function
- georgewsinger 9y agoI see. The error makes sense now.
- oldandtired 9y agoDepending on your system, 1(1) is quite sensible, That is applying 1 to a list of parameters just returns the 1st parameter. This is a matter of the semantics that one uses when application is run against any value. 1(1) -> 1 Just because the common idea of application is that it only applies to functions does not mean that application applied to other types is nonsensical and should end up with a runtime error. If your language allows application to be defined for different types, then the type system should be capable of determining the type that returns from application. A practical example of a language in which application is valid for integers is Unicon/Icon. Both functions and integers have specific semantics with regards to application. And failure is an option.