Skip to content

Instantly share code, notes, and snippets.

@patricoferris
Created October 8, 2019 23:54
Show Gist options
  • Save patricoferris/cd22b3482b6b03b1377b081c6cd74367 to your computer and use it in GitHub Desktop.
Save patricoferris/cd22b3482b6b03b1377b081c6cd74367 to your computer and use it in GitHub Desktop.
(* A fibonacci function *)
let rec fib x = if x = 0 || x = 1 then 1 else fib (x - 1) + fib (x - 2);;
(* A function that allows for partial evaluation *)
let h x = let z = fib x in fun y -> y + z;;
(* fib 30 will only be calculated once *)
List.map (h 30) [1; 2; 3; 4; 5];;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment