Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.52 KB | None | 0 0
  1. let rec countA (a:int) = function
  2.     | Leaf          -> 0
  3.     | Node(tl,n,tr) -> countA a tl + countA a tr + (a+1)
  4.  
  5. let rec countAC t (a:int) c =
  6.     match t with
  7.     | Leaf          -> c 0
  8.     | Node(tl,n,tr) -> countAC tl a (fun vl -> countAC tr a (fun vr -> c(a+vl+vr+1)))
  9.  
  10. let rec count = function
  11.     | Leaf          -> 0
  12.     | Node(tl,n,tr) -> count tl + count tr + 1
  13.  
  14. let rec countC t c =
  15.     match t with
  16.     | Leaf          -> c 0
  17.     | 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