Skip to content

Instantly share code, notes, and snippets.

@Octachron
Last active January 5, 2017 11:38
Show Gist options
  • Save Octachron/a2c2a97bb432504bde5ebbdf3bbb2ef9 to your computer and use it in GitHub Desktop.
Save Octachron/a2c2a97bb432504bde5ebbdf3bbb2ef9 to your computer and use it in GitHub Desktop.
type 'a t =
| Leaf of 'a
| Node of (int -> 'a) t * (int -> 'a) t
let l = Leaf ();;
let f n = n
let g n k = n + k
let n = Node(Leaf f, Leaf f)
let n2= Node( Node(Leaf g, Leaf g), Leaf f)
let rec apply: 'a. 'a t -> ('a -> int) -> int =
fun t k -> match t with
| Leaf m -> k m
| Node(l, r) ->
apply l (fun f -> k (f 0)) + apply r (fun f -> k (f 1) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment