Advertisement
kator

Untitled

Mar 13th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. open Printf;;
  2. let a = 5;;
  3. let b = 5;;
  4. (*
  5. printf "%i\n" 10;;
  6. printf "%f\n" 10.0;;
  7. printf "%s\n" "ala";;
  8. printf "%s\n" ("ala" ^ " i kot.");;
  9.  
  10.  
  11. 1 + match [1;2;3] with
  12. [] -> 0
  13. | head ::tail -> printf "%i\n" head; head;;
  14. *)
  15.  
  16. let len list =
  17. let rec f n = function
  18. | [] -> n
  19. | _::t -> f (n+1) t
  20. in
  21. f 0 list;;
  22.  
  23. (*
  24. let rec len = function
  25. [] -> 0
  26. | _::rest -> 1 + len rest;;
  27.  
  28.  
  29. printf "%i\n" (len [1;2;3;4;5]); 0;;
  30. *)
  31.  
  32. (* drukowanie listy *)
  33.  
  34. let print_int_list l =
  35. let rec string_of_list l = match l with
  36. [] -> ""
  37. | h::t -> (string_of_int h)^";"^(string_of_list t)
  38.  
  39. in
  40. Printf.printf "[%s]\n" (string_of_list l);;
  41.  
  42. print_int_list [1;2;3;4];;
  43. print_int_list [5;4];;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement