Want more features on Pastebin? Sign Up, it's FREE!
Guest

Juliet

By: a guest on Jan 2nd, 2010  |  syntax: OCaml  |  size: 0.61 KB  |  views: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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"
clone this paste RAW Paste Data