Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cps/cartesian.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ let rec mapk f l k =
| h :: tl -> mapk f tl (fun s -> k (f h :: s))
;;

let rec appendk l1 l2 k =
match l1 with
| [] -> k l2
| h :: tl -> appendk tl l2 (fun s -> k (h :: s))
;;

let rec concatk xs k =
match xs with
| [] -> k []
| h :: tl -> concatk tl (fun s -> k (h @ s))
| h :: tl -> concatk tl (fun s1 -> appendk h s1 (fun s2 -> k s2))
;;

let cartesiank l1 l2 k =
Expand Down
11 changes: 9 additions & 2 deletions src/cps/monad_list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ module ListCPS = struct
| h :: tl -> mapk f tl (fun s -> k (f h :: s))
;;

let rec appendk l1 l2 k =
match l1 with
| [] -> k l2
| h :: tl -> appendk tl l2 (fun s -> k (h :: s))
;;

let rec concatk xs k =
match xs with
| [] -> k []
| h :: tl -> concatk tl (fun s -> k (h @ s))
| h :: tl -> concatk tl (fun s1 -> appendk h s1 (fun s2 -> k s2))
;;

let bindk m f k = mapk f m (fun s -> concatk s k)
let bindk m f k = mapk f m (fun s1 -> concatk s1 (fun s2 -> k s2))
let bind m f = bindk m f (fun x -> x)
let fail _ = []
end

Expand Down