summaryrefslogtreecommitdiff
path: root/src/Collections.ml
diff options
context:
space:
mode:
authorSon Ho2022-01-21 15:26:49 +0100
committerSon Ho2022-01-21 15:26:49 +0100
commitfddf0195bb77932ca9a8c851d330df99988fd361 (patch)
tree76860c80a0fe9ec167e437143545047053341436 /src/Collections.ml
parentc7046673306d8d8ddac7f815f523a4938e9802c9 (diff)
Start working on the generation of the symbolic AST
Diffstat (limited to 'src/Collections.ml')
-rw-r--r--src/Collections.ml14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Collections.ml b/src/Collections.ml
index b73bc3b6..54d0acac 100644
--- a/src/Collections.ml
+++ b/src/Collections.ml
@@ -9,6 +9,8 @@ module List = struct
`split_at ls i` splits `ls` into two lists where the first list has
length `i`.
+
+ Raise `Failure` if the list is too short.
*)
let rec split_at (ls : 'a list) (i : int) =
if i < 0 then raise (Invalid_argument "split_at take positive integers")
@@ -21,6 +23,18 @@ module List = struct
| x :: ls' ->
let ls1, ls2 = split_at ls' (i - 1) in
(x :: ls1, ls2)
+
+ (** Pop the last element of a list
+
+ Raise `Failure` if the list is empty.
+ *)
+ let rec pop_last (ls : 'a list) : 'a list * 'a =
+ match ls with
+ | [] -> raise (Failure "The list is empty")
+ | [ x ] -> ([], x)
+ | x :: ls ->
+ let ls, last = pop_last ls in
+ (x :: ls, last)
end
module type OrderedType = sig