diff options
author | Eduardo Julian | 2018-07-04 18:28:38 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-04 18:28:38 -0400 |
commit | 01ca61865cf816808151fdecccd84bc6da8194ff (patch) | |
tree | 7df603f4429a89be2673b102b1ee85ec754e3c3b /stdlib/source/lux/lang | |
parent | 971d5d8aceb5087d3b3aef9db45abe9bc9c7c844 (diff) |
- Implemented ":cast" macro, and used it to implement both ":abstraction" and ":representation".
- Fix: You shouldn't be able to resolve tags if you haven't imported a module (even if they are exported).
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/lang/type.lux | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/stdlib/source/lux/lang/type.lux b/stdlib/source/lux/lang/type.lux index 36e6a74a8..acc3d9046 100644 --- a/stdlib/source/lux/lang/type.lux +++ b/stdlib/source/lux/lang/type.lux @@ -1,13 +1,16 @@ (.module: {#.doc "Basic functionality for working with types."} [lux #- function] (lux (control [equality #+ Eq] - [monad #+ do Monad]) + [monad #+ do Monad] + ["p" parser]) (data [text "text/" Monoid<Text> Eq<Text>] - [ident "ident/" Eq<Ident>] + [ident "ident/" Eq<Ident> Codec<Text,Ident>] [number "nat/" Codec<Text,Nat>] [maybe] - (coll [list #+ "list/" Monad<List> Monoid<List> Fold<List>])) - (macro [code]) + (coll [list #+ "list/" Functor<List> Monoid<List> Fold<List>])) + [macro] + (macro [code] + ["s" syntax #+ syntax:]) )) ## [Utils] @@ -275,7 +278,7 @@ (<ctor> type (<name> types'))))] [variant Nothing #.Sum] - [tuple Any #.Product] + [tuple Any #.Product] ) (def: #export (function inputs output) @@ -330,3 +333,34 @@ (case level +0 elem-type _ (|> elem-type (array (dec level)) (list) (#.Primitive "#Array")))) + +(syntax: #export (:log! {input (p.alt s.symbol + s.any)}) + (case input + (#.Left valueN) + (do @ + [cursor macro.cursor + valueT (macro.find-type valueN) + #let [_ (log! ($_ text/compose + ":log!" " @ " (.cursor-description cursor) "\n" + (ident/encode valueN) " : " (..to-text valueT) "\n"))]] + (wrap (list (' [])))) + + (#.Right valueC) + (macro.with-gensyms [g!value] + (wrap (list (` (.let [(~ g!value) (~ valueC)] + (..:log! (~ g!value))))))))) + +(syntax: #export (:cast {type-vars (s.tuple (p.some s.local-symbol))} + input + output + {value (p.maybe s.any)}) + (let [casterC (` (: (All [(~+ (list/map code.local-symbol type-vars))] + (-> (~ input) (~ output))) + (|>> :assume)))] + (case value + #.None + (wrap (list casterC)) + + (#.Some value) + (wrap (list (` ((~ casterC) (~ value)))))))) |