Skip to content

Commit

Permalink
Use effect syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
johnridesabike committed Feb 7, 2025
1 parent 337b9b7 commit 6150bb6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- macos-latest
- windows-latest
ocaml-compiler:
- 5.2.x
- 5.3.x

runs-on: ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
profile = default
version = 0.27.0
ocaml-version = 5.3
break-sequences = false
11 changes: 4 additions & 7 deletions acutis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,10 @@ end = struct
type _ Effect.t += Yield : a -> unit Effect.t
end in
let yield v = Effect.perform (M.Yield v) in
let retc () = Seq.Nil in
let effc : type b.
b Effect.t -> ((b, _) Effect.Deep.continuation -> _) option = function
| M.Yield v -> Some (fun k -> Seq.Cons (v, Effect.Deep.continue k))
| _ -> None
in
fun () -> Effect.Deep.match_with f yield { retc; exnc = raise; effc }
fun () ->
match f yield with
| () -> Seq.Nil
| effect M.Yield v, k -> Seq.Cons (v, Effect.Deep.continue k)

let iter s f = Seq.iter f s
let string_to_seq = String.to_seq
Expand Down
2 changes: 1 addition & 1 deletion acutis.opam
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ doc: "https://johnridesa.bike/acutis/"
bug-reports: "https://github.com/johnridesabike/acutis/issues"
depends: [
"dune" {>= "3.13"}
"ocaml" {>= "5.2"}
"ocaml" {>= "5.3"}
"menhir"
"yojson"
"dune-build-info"
Expand Down
17 changes: 6 additions & 11 deletions acutis_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,14 @@ module Promise = struct
Js.Unsafe.inject (Js.wrap_callback reject);
|]

module E = Effect
module ED = Effect.Deep
type _ Effect.t += Await : 'a t -> 'a Effect.t

type _ E.t += Await : 'a t -> 'a E.t
let await p = Effect.perform (Await p)

let await p = E.perform (Await p)

let effc : type a. a E.t -> ((a, 'b t) ED.continuation -> 'b t) option =
function
| Await p -> Some (fun k -> then_ p (ED.continue k) (ED.discontinue k))
| _ -> None

let handle_await f = ED.try_with f () { effc }
let handle_await f =
match f () with
| x -> x
| effect Await p, k -> Effect.Deep.(then_ p (continue k) (discontinue k))
end

let fname_to_compname s =
Expand Down
2 changes: 1 addition & 1 deletion acutis_js.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ doc: "https://johnridesa.bike/acutis/"
bug-reports: "https://github.com/johnridesabike/acutis/issues"
depends: [
"dune" {>= "3.13"}
"ocaml" {>= "5.0"}
"ocaml"
"acutis" {= version}
"js_of_ocaml" {>= "5.8.1"}
"js_of_ocaml-compiler"
Expand Down
5 changes: 2 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ compile them to self-contained JavaScript files.
")
(depends
(ocaml
(>= 5.2))
(>= 5.3))
menhir
yojson
dune-build-info
Expand All @@ -44,8 +44,7 @@ compile them to self-contained JavaScript files.
(synopsis "A virtual package containing the Acutis JavaScript dependencies")
(allow_empty)
(depends
(ocaml
(>= 5.0))
ocaml
(acutis
(= :version))
(js_of_ocaml
Expand Down

0 comments on commit 6150bb6

Please sign in to comment.