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
(* 1 *)
let rec nth l n =
match n with
| 0 -> hd l
| i when i > 0 && i < (length l) -> nth (tl l) (i - 1)
| _ -> raise (Failure "list index out of bounds")
match l with
| [] -> raise (Failure "list index out of bounds")
| h::t -> if n = 0 then h else nth t (n - 1)
;;
(* 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