Anonymous user
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
A function is just a value that wants arguments:
func1 f = f "a string"
func2 s = "func2 called with " ++ s
main =
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]] ==
|