-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.ml
More file actions
50 lines (38 loc) · 1.27 KB
/
Copy pathutility.ml
File metadata and controls
50 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
exception Error of string
(* for compatibility with 4.07 *)
module MyOption =
struct
let bind (x : 'a option) (f : 'a -> 'b option) : 'b option =
(match x with
| None -> None
| Some x' -> (f x'))
end;;
module List =
struct
include List
let rec remove1 x ls =
(match ls with
| [] -> []
| a::ls' -> (if (x = a) then ls' else a::(remove1 x ls')))
let rec find_pair2 (ls1 : 'a list) (ls2 : 'b list) (rel : 'a -> 'b -> bool) : ('a * 'b) option =
(match ls1 with
| [] -> None
| x::ls1' -> (match (find_opt (rel x) ls2) with
| None -> (find_pair2 ls1' ls2 rel)
| Some y -> Some (x,y)))
let rec nth_tl (xs : 'a list) (i : int) : 'a list =
(if i = 0 then xs
else (nth_tl (tl xs) (i - 1)))
let rec index (xs : 'a list) (x : 'a) : int =
(match xs with
| [] -> raise (Error "element not in list")
| x'::xs' -> (if x = x' then 0 else (1 + (index xs' x))))
let range i k : int list =
(init k (fun x -> x + i))
end;;
module String =
struct
include String
let explode (str : string) : char list =
(List.init (length str) (get str))
end;;