
Juliet
By: a guest on
Jan 2nd, 2010 | syntax:
OCaml | size: 0.61 KB | hits: 44 | expires: Never
let rec take count l =
match count, l with
| 0, xs -> []
| n, x::xs -> x::take (n - 1) xs
| n, [] -> failwith "Index out of range"
let rec skip count l =
match count, l with
| 0, xs -> xs
| n, x::xs -> skip (n - 1) xs
| n, [] -> failwith "Index out of range"
let rec insert index v l =
match index, l with
| 0, xs -> v::xs
| n, x::xs -> x::insert (n - 1) v xs
| n, [] -> failwith "Index out of range"
let rec delete index l =
match index, l with
| 0, x::xs -> xs
| n, x::xs -> x::delete (n - 1) xs
| n, [] -> failwith "Index out of range"