diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/compiler/default/phase/synthesis/function.lux | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/stdlib/source/lux/compiler/default/phase/synthesis/function.lux b/stdlib/source/lux/compiler/default/phase/synthesis/function.lux index 8a85b9873..3c89ae063 100644 --- a/stdlib/source/lux/compiler/default/phase/synthesis/function.lux +++ b/stdlib/source/lux/compiler/default/phase/synthesis/function.lux @@ -1,13 +1,9 @@ (.module: [lux (#- function) [control - ["." monad (#+ do)] - ["." state] - pipe - ["ex" exception (#+ exception:)]] + ["." monad (#+ do)]] [data - ["." maybe ("maybe/." Monad<Maybe>)] - ["." error] + ["." maybe] [collection ["." list ("list/." Functor<List> Monoid<List> Fold<List>)] ["dict" dictionary (#+ Dictionary)]]]] @@ -48,7 +44,7 @@ (-> Phase Phase) (.function (_ exprA) (let [[funcA argsA] (unfold exprA)] - (do (state.Monad<State'> error.Monad<Error>) + (do ///.Monad<Operation> [funcS (synthesize funcA) argsS (monad.map @ synthesize argsA) locals //.locals] @@ -64,23 +60,11 @@ _ (wrap (//.function/apply [funcS argsS]))))))) -(def: (prepare up down) - (-> Arity Arity (Transform Synthesis)) - (.function (_ body) - (if (nested? up) - (#.Some body) - (loop.recursion down body)))) - -(exception: #export (cannot-prepare-function-body {_ []}) - "") - -(def: return - (All [a] (-> (Maybe a) (Operation a))) - (|>> (case> (#.Some output) - (:: ///.Monad<Operation> wrap output) - - #.None - (///.throw cannot-prepare-function-body [])))) +(def: (prepare up down body) + (-> Arity Arity Synthesis Synthesis) + (if (nested? up) + body + (maybe.default body (loop.recursion down body)))) (def: #export (function synthesize environment body) (-> Phase Environment Analysis (Operation Synthesis)) @@ -127,10 +111,10 @@ (^ (//.function/abstraction [env' down-arity' bodyS'])) (let [arity' (inc down-arity')] (|> (prepare function-arity arity' bodyS') - (maybe/map (|>> [up-environment arity'] //.function/abstraction)) - ..return)) + [up-environment arity'] //.function/abstraction + wrap)) _ (|> (prepare function-arity 1 bodyS) - (maybe/map (|>> [up-environment 1] //.function/abstraction)) - ..return)))) + [up-environment 1] //.function/abstraction + wrap)))) |