Skip to content

Instantly share code, notes, and snippets.

@Isweet
Created October 6, 2015 21:22
Show Gist options
  • Save Isweet/102d2150f0dbde7333b1 to your computer and use it in GitHub Desktop.
Save Isweet/102d2150f0dbde7333b1 to your computer and use it in GitHub Desktop.
Functions as values in OCaml
let comp = fun f -> (fun g -> (fun x -> f (g x)));;
let doublesquare = comp (fun x -> x + x) (fun y -> y * y);;
print_int (doublesquare 5); print_newline ();;
(* expect 50 *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment