Guest User

Untitled

a guest
Sep 13th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.33 KB | None | 0 0
  1. (* Problem 01: Find the last element of a list *)
  2.  
  3. exception Empty_list;;
  4.  
  5. let my_last l = ( List.nth l ((List.length l) -1 ) );;
  6.  
  7. let rec my_last_2 l =
  8.     match l with
  9.         []  -> raise Empty_list
  10.     |   h::[]   -> h
  11.     |   h::t    -> my_last_2 t
  12. ;;
  13.  
  14. (** test **)
  15. Printf.printf "%s\n" ( my_last ["a";"b";"c";"d"] );;
Add Comment
Please, Sign In to add comment