Higher-order functions: Difference between revisions

→‎[[Haskell]]: replaced with clearer examples
No edit summary
(→‎[[Haskell]]: replaced with clearer examples)
Line 165:
==[[Haskell]]==
[[Category:Haskell]]
'''Interpreter:''' [[GHC|GHCi]] 6.6
 
applyFunc f x = f x
A function is just a value that wants arguments:
func1 f = f "a string"
func2 s = "func2 called with " ++ s
main = printputStrLn $ applyFuncfunc1 log 5func2
Or, with an anonymous function:
func f = f 1 2
main = print $ func (\x y -> x+y)
-- output: 3
Note that <tt>func (\x y -> x+y)</tt> is equivalent to <tt>func (+)</tt>. (Operators are functions too.)
 
== [[JavaScript]] ==
Anonymous user