First-class functions/Use numbers analogously: Difference between revisions

Line 509:
 
=={{header|OCaml}}==
{{incorrect|OCaml|Compare and contrast the resultant program with the corresponding entry in First-class functions.}}
<lang ocaml># let x, xi, y, yi = 2.0, 0.5, 4.0, 0.25 ;;
 
<lang ocaml># let zx = x +2. y0;;
and zi = 1.0 /. (x +. y) ;;
 
# let multiplier n1 n2y = (fun m -> n1 *4. n2 *. m) 0;;
 
# let numlistz = [x; +. y; z];
and numlisti = [xi; yi; zi] ;;
 
# let funclistcoll = [sin x; cosy; cubez];;
# List.map2 (fun n inv -> (multiplier n inv) 0.5) numlist numlisti ;;
- : float list = [0.5; 0.5; 0.5]</lang>
 
<lang ocaml># let cubeinv_coll = functionList.map (fun x -> x1.0 */. x) coll;;
 
# let crootmultiplier n1 n2 = function(fun xt -> xn1 ** (1. /.n2 3*.0) t);;
 
# let composefunc_list = List.map2 (fun f1n f2inv -> (funmultiplier xn -> f1(f2 xinv)) coll inv_coll;;
 
# List.map (fun f -> f 0.5) func_list;;
# let funclist = [sin; cos; cube]
- : andfloat funclistilist = [asin0.5; acos0.5; croot0.5] ;;
 
</lang>
# List.map2 (fun inversef f -> (compose inversef f) 0.5) funclist funclisti ;;
- : float list = [0.5; 0.499999999999999889; 0.629960524947436706]</lang>
 
=={{header|Oz}}==
Anonymous user