SHARE
TWEET

Juliet

a guest Jan 2nd, 2010 52 Never
  1. let rec take count l =
  2.     match count, l with
  3.     | 0, xs -> []
  4.     | n, x::xs -> x::take (n - 1) xs
  5.     | n, [] -> failwith "Index out of range"
  6.  
  7. let rec skip count l =
  8.     match count, l with
  9.     | 0, xs -> xs
  10.     | n, x::xs -> skip (n - 1) xs
  11.     | n, [] -> failwith "Index out of range"
  12.  
  13. let rec insert index v l =
  14.     match index, l with
  15.     | 0, xs -> v::xs
  16.     | n, x::xs -> x::insert (n - 1) v xs
  17.     | n, [] -> failwith "Index out of range"
  18.  
  19. let rec delete index l =
  20.     match index, l with
  21.     | 0, x::xs -> xs
  22.     | n, x::xs -> x::delete (n - 1) xs
  23.     | n, [] -> failwith "Index out of range"
RAW Paste Data
Top