Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.20 KB | None | 0 0
  1. let memoize f =
  2.   let table = Hashtbl.Poly.create () in
  3.   fun x ->
  4.   match Hashtbl.find table x with
  5.   | Some y -> y
  6.   | None ->
  7.      let y = f x in
  8.      Hashtbl.add_exn table ~key:x ~data:y;
  9.      y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement