Skip to content

Commit

Permalink
Rename std to syntax and add more list functions in Result
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Sep 5, 2024
1 parent 73e2bc5 commit 78e61da
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
solver
solver_intf
solver_dispatcher
std
syntax
symbol
statistics
ty
Expand Down
14 changes: 0 additions & 14 deletions src/std/std.ml

This file was deleted.

47 changes: 47 additions & 0 deletions src/stdlib/syntax.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Option = struct
include Option

let ( let* ) v f = bind v f

let ( let+ ) v f = map f v
end

module Result = struct
include Result

let ( let* ) v f = Result.bind v f

let ( let+ ) v f = Result.map f v

let rec list_iter f = function
| [] -> Ok ()
| hd :: tl ->
let* () = f hd in
list_iter f tl

let list_map f v =
let rec list_map_cps f v k =
match v with
| [] -> k (Ok [])
| hd :: tl ->
list_map_cps f tl (fun rest ->
let* rest in
let* hd' = f hd in
k (Ok (hd' :: rest)) )
in
list_map_cps f v Fun.id

let list_filter_map f v =
let rec list_filter_map_cps f v k =
match v with
| [] -> k (Ok [])
| hd :: tl ->
list_filter_map_cps f tl (fun rest ->
let* rest in
match f hd with
| Error _ as e -> k e
| Ok None -> k (Ok rest)
| Ok (Some v) -> k (Ok (v :: rest)) )
in
list_filter_map_cps f v Fun.id
end

0 comments on commit 78e61da

Please sign in to comment.