From 7fd340fa9b8eb55241c895b19a5c6239d59d66a7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 28 Jul 2023 17:25:05 +0200 Subject: [PATCH] pure roc nest/nestHelp --- .../cli_testing_examples/benchmarks/Deriv.roc | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/cli_testing_examples/benchmarks/Deriv.roc b/crates/cli_testing_examples/benchmarks/Deriv.roc index 974c1ada668..7e4d22a6c29 100644 --- a/crates/cli_testing_examples/benchmarks/Deriv.roc +++ b/crates/cli_testing_examples/benchmarks/Deriv.roc @@ -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]