Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.47 KB | None | 0 0
  1. let rec count = function
  2.  | Leaf          -> 0
  3.  | Node(tl,n,tr) -> count tl + count tr + 1;;
  4.  
  5. let rec countA tree n =
  6.  match tree with
  7.  | Leaf -> n
  8.  | Node(tl,_,tr) -> countA tl (countA tr (n+1));;
  9.  
  10. let rec countAC tree n c =
  11.  match tree with
  12.  | Leaf -> c n
  13.  | Node(tl,_,tr) -> countAC tl (n+1) (fun vl -> countAC tr vl c);;
  14.  
  15. let rec countC t c =
  16.  match t with
  17.  | Leaf          -> c 0
  18.  | Node(tl,n,tr) -> countC tl (fun vl -> countC tr (fun vr -> c(vl+vr+1)));;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement