Advertisement
Guest User

Bad Ocaml

a guest
Sep 5th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.35 KB | None | 0 0
  1. (* Counts the number of instances of num in x::xs
  2.  * for instance, (countNum ([1;1;2;3], 0, 1)) should return 2*)
  3.  
  4. let rec countNum (lst, soFar, num) =
  5.    match lst with
  6.       | []  -> soFar
  7.       | num::xs -> countNum (xs, (soFar+1), num)
  8.       | _::xs   -> countNum (xs, soFar, num);;
  9.  
  10. (* With this implementation the above example returns 4 *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement