Skip to content

Commit

Permalink
pure roc nest/nestHelp
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jul 28, 2023
1 parent ce640fe commit 7fd340f
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions crates/cli_testing_examples/benchmarks/Deriv.roc
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ main =
Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."

nest : (I64, Expr -> IO Expr), I64, Expr -> IO Expr
nest = \f, n, e -> Task.loop { s: n, f, m: n, x: e } nestHelp

State : { s : I64, f : I64, Expr -> IO Expr, m : I64, x : Expr }
nestHelp : I64, (I64, Expr -> IO Expr), I64, Expr -> IO Expr
nestHelp = \s, f, m, x -> when m is
0 -> Task.succeed x
_ ->
w <- Task.after (f (s - m) x)
nestHelp s f (m - 1) w

nestHelp : State -> IO [Step State, Done Expr]
nestHelp = \{ s, f, m, x } ->
when m is
0 -> Task.succeed (Done x)
_ ->
w <- Task.after (f (s - m) x)

Task.succeed (Step { s, f, m: (m - 1), x: w })
nest : (I64, Expr -> IO Expr), I64, Expr -> IO Expr
nest = \f, n, e -> nestHelp n f n e

Expr : [Val I64, Var Str, Add Expr Expr, Mul Expr Expr, Pow Expr Expr, Ln Expr]

Expand Down

0 comments on commit 7fd340f

Please sign in to comment.