Hacker News new | past | comments | ask | show | jobs | submit login

What you need is that functions are values in your language. Lambdas are just a notation for function values. Typed lambda calculus is the internal language of cartesian closed categories and function values are then called internal morphisms. The composition above is then the internal composition of internal morphisms. It would be possible for external composition to be already defined by the language, take the unix shell for example, with its buildin "|" operator. But if you want to be able to define function composition within the language, you need to have something like lambda.



> What you need is that functions are values in your language.

Well yeah, that's what I meant by higher order functions.

> Lambdas are just a notation for function values.

But regular (named) functions can still be used as function values. So this doesn't explain why you need things like lambdas in order to implement function composition.

> Typed lambda calculus is the internal language of cartesian closed categories and function values are then called internal morphisms. The composition above is then the internal composition of internal morphisms.

Ok bud.

> But if you want to be able to define function composition within the language, you need to have something like lambda.

Well I could implement function composition without the syntactic construct lambda:

(.) g f x = g (f x)

I am not using any lambdas, in the sense of anonymous functions or closures. To implement function composition with a lambda is more of a stylistic choice, in this case. Granted, maybe functions-used-as-values are also lambdas, for all I know.


(.) g f x = g (f x)

Interesting. I might say that partial application is a kind of closure. Certainly, it winds up the same - "function carrying some data that it uses internally". I think you are correct that compose and apply does not require closures of any sort.


Well (.) g f x = g (f x) in Haskell is just sugar for (.) g f = \x -> g (f x), which ultimately is turned into (.) = \g -> \f -> \x -> g (f x)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: