diff options
Diffstat (limited to 'stdlib/source/lux/language/compiler/synthesis/case.lux')
-rw-r--r-- | stdlib/source/lux/language/compiler/synthesis/case.lux | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/stdlib/source/lux/language/compiler/synthesis/case.lux b/stdlib/source/lux/language/compiler/synthesis/case.lux index 7dd8b3157..de7a4f9fd 100644 --- a/stdlib/source/lux/language/compiler/synthesis/case.lux +++ b/stdlib/source/lux/language/compiler/synthesis/case.lux @@ -11,42 +11,43 @@ format] [number ("frac/" Equivalence<Frac>)] [collection [list ("list/" Fold<List> Monoid<List>)]]]] - [///reference] - [///compiler (#+ Operation) ("operation/" Monad<Operation>)] - [///analysis (#+ Pattern Match Analysis)] - [// (#+ Path Synthesis)] - [//function]) + [// (#+ Path Synthesis) + [function] + [/// + [reference] + [compiler (#+ Operation) ("operation/" Monad<Operation>)] + [analysis (#+ Pattern Match Analysis)]]]) (def: (path' pattern bodyC) (-> Pattern (Operation //.State Path) (Operation //.State Path)) (case pattern - (#///analysis.Simple simple) + (#analysis.Simple simple) (case simple - #///analysis.Unit + #analysis.Unit bodyC (^template [<from> <to>] (<from> value) (operation/map (|>> (#//.Seq (#//.Test (|> value <to>)))) bodyC)) - ([#///analysis.Bool #//.Bool] - [#///analysis.Nat (<| #//.I64 .i64)] - [#///analysis.Int (<| #//.I64 .i64)] - [#///analysis.Rev (<| #//.I64 .i64)] - [#///analysis.Frac #//.F64] - [#///analysis.Text #//.Text])) + ([#analysis.Bool #//.Bool] + [#analysis.Nat (<| #//.I64 .i64)] + [#analysis.Int (<| #//.I64 .i64)] + [#analysis.Rev (<| #//.I64 .i64)] + [#analysis.Frac #//.F64] + [#analysis.Text #//.Text])) - (#///analysis.Bind register) - (<| (do ///compiler.Monad<Operation> + (#analysis.Bind register) + (<| (do compiler.Monad<Operation> [arity //.scope-arity]) - (:: @ map (|>> (#//.Seq (#//.Bind (if (//function.nested? arity) + (:: @ map (|>> (#//.Seq (#//.Bind (if (function.nested? arity) (n/+ (dec arity) register) register))))) //.with-new-local bodyC) - (#///analysis.Complex _) - (case (///analysis.variant-pattern pattern) + (#analysis.Complex _) + (case (analysis.variant-pattern pattern) (#.Some [lefts right? value-pattern]) (operation/map (|>> (#//.Seq (#//.Access (#//.Side (if right? (#.Right lefts) @@ -54,11 +55,11 @@ (path' value-pattern bodyC)) #.None - (let [tuple (///analysis.tuple-pattern pattern) + (let [tuple (analysis.tuple-pattern pattern) tuple/last (dec (list.size tuple))] (list/fold (function (_ [tuple/idx tuple/member] thenC) (case tuple/member - (#///analysis.Simple #///analysis.Unit) + (#analysis.Simple #analysis.Unit) thenC _ @@ -126,15 +127,15 @@ (def: #export (synthesize synthesize^ inputA [headB tailB+]) (-> //.Synthesizer Analysis Match (Operation //.State Synthesis)) - (do ///compiler.Monad<Operation> + (do compiler.Monad<Operation> [inputS (synthesize^ inputA)] (with-expansions [<unnecesary-let> - (as-is (^multi (^ (#///analysis.Reference (///reference.local outputR))) + (as-is (^multi (^ (#analysis.Reference (reference.local outputR))) (n/= inputR outputR)) (wrap inputS)) <let> - (as-is [[(#///analysis.Bind inputR) headB/bodyA] + (as-is [[(#analysis.Bind inputR) headB/bodyA] #.Nil] (case headB/bodyA <unnecesary-let> @@ -145,16 +146,16 @@ headB/bodyS (//.with-new-local (synthesize^ headB/bodyA))] (wrap (//.branch/let [inputS - (if (//function.nested? arity) + (if (function.nested? arity) (n/+ (dec arity) inputR) inputR) headB/bodyS]))))) <if> - (as-is (^or (^ [[(///analysis.pattern/bool true) thenA] - (list [(///analysis.pattern/bool false) elseA])]) - (^ [[(///analysis.pattern/bool false) elseA] - (list [(///analysis.pattern/bool true) thenA])])) + (as-is (^or (^ [[(analysis.pattern/bool true) thenA] + (list [(analysis.pattern/bool false) elseA])]) + (^ [[(analysis.pattern/bool false) elseA] + (list [(analysis.pattern/bool true) thenA])])) (do @ [thenS (synthesize^ thenA) elseS (synthesize^ elseA)] |