Commit e73a625e authored by Taddeüs Kroes's avatar Taddeüs Kroes

funclang taddeus series 3: prettified nth function.

parent e3902d0a
...@@ -2,10 +2,9 @@ open List ...@@ -2,10 +2,9 @@ open List
(* 1 *) (* 1 *)
let rec nth l n = let rec nth l n =
match n with match l with
| 0 -> hd l | [] -> raise (Failure "list index out of bounds")
| i when i > 0 && i < (length l) -> nth (tl l) (i - 1) | h::t -> if n = 0 then h else nth t (n - 1)
| _ -> raise (Failure "list index out of bounds")
;; ;;
(* 2 *) (* 2 *)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment