Higher-order functions: Difference between revisions

added standard ml
m (bunch of +lang)
(added standard ml)
Line 771:
</lang>
Note that <tt>(func (lambda (x y) (+ x y)))</tt> is equivalent to <tt>(func +)</tt>. (Operators are functions too.)
 
=={{header|Standard ML}}==
 
<lang sml>
- fun func1 f = f "a string";
val func1 = fn : (string -> 'a) -> 'a
- fun func2 s = "func2 called with " ^ s;
val func2 = fn : string -> string
 
- print (func1 func2 ^ "\n");
func2 called with a string
val it = () : unit
</lang>
 
Or, with an anonymous function:
<lang ocaml>
- fun func f = f (1, 2);
val func = fn : (int * int -> 'a) -> 'a
 
- print (Int.toString (func (fn (x, y) => x + y)) ^ "\n");
3
val it = () : unit
</lang>
Note that <tt>func (fn (x, y) => x + y)</tt> is equivalent to <tt>func op+</tt>. (Operators are functions too.)
 
=={{header|Tcl}}==
Anonymous user