diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/type/refinement.lux | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/stdlib/source/library/lux/type/refinement.lux b/stdlib/source/library/lux/type/refinement.lux index 304d7a07b..c4ac00c29 100644 --- a/stdlib/source/library/lux/type/refinement.lux +++ b/stdlib/source/library/lux/type/refinement.lux @@ -9,7 +9,7 @@ ["[0]" macro [syntax {"+" syntax:}]] ["[0]" type - abstract]]]) + [abstract {"-" pattern}]]]]) (abstract: .public (Refined t %) (Record @@ -25,14 +25,14 @@ (-> (Predicate t) (Refiner t %)))) (function (_ value) (if (predicate value) - {.#Some (:abstraction [#value value - #predicate predicate])} + {.#Some (abstraction [#value value + #predicate predicate])} {.#None}))) (template [<name> <output> <slot>] [(def: .public <name> (All (_ t %) (-> (Refined t %) <output>)) - (|>> :representation (the <slot>)))] + (|>> representation (the <slot>)))] [value t #value] [predicate (Predicate t) #predicate] @@ -43,11 +43,11 @@ (-> (-> t t) (-> (Refined t %) (Maybe (Refined t %))))) (function (_ refined) - (let [(open "_[0]") (:representation refined) + (let [(open "_[0]") (representation refined) value' (transform _#value)] (if (_#predicate value') - {.#Some (:abstraction [..#value value' - ..#predicate _#predicate])} + {.#Some (abstraction [..#value value' + ..#predicate _#predicate])} {.#None})))) ) @@ -85,9 +85,21 @@ {.#Item head no}])))) (syntax: .public (type [refiner <code>.any]) - (macro.with_symbols [g!t g!%] - (in (list (` ((~! type.:by_example) [(~ g!t) (~ g!%)] - (..Refiner (~ g!t) (~ g!%)) - (~ refiner) - - (..Refined (~ g!t) (~ g!%)))))))) + ... TODO: Switch to the cleaner approach ASAP. + (macro.with_symbols [g!t g!% g!_ g!:refiner:] + (in (list (` (let [... (~ g!_) (.is (.Ex ((~ g!_) (~ g!t) (~ g!%)) + ... (..Refined (~ g!t) (~ g!%))) + ... (~ refiner)) + ] + (.case (.type_of (~ refiner)) + {.#Apply (~ g!%) {.#Apply (~ g!t) (~ g!:refiner:)}} + (.type (..Refined (~ g!t) (~ g!%))) + + (~ g!_) + (.undefined)))) + ... (` ((~! type.by_example) [(~ g!t) (~ g!%)] + ... (..Refiner (~ g!t) (~ g!%)) + ... (~ refiner) + + ... (..Refined (~ g!t) (~ g!%)))) + )))) |