diff options
author | Eduardo Julian | 2015-04-25 17:30:54 -0400 |
---|---|---|
committer | Eduardo Julian | 2015-04-25 17:30:54 -0400 |
commit | cc8f12a30f0f7144e9ce0a2846b30d4d9c36d0eb (patch) | |
tree | 8212f3e71a7e2ce0f672cce118ba703153bfe3de /source | |
parent | d366abe19aaf9b688312d2f845f6771b8478cc0c (diff) |
- More accurate AllT environment management by using (Maybe TypeEnv) instead of TypeEnv. The performance of the type-checker also improved thanks to that.
Diffstat (limited to 'source')
-rw-r--r-- | source/lux.lux | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/source/lux.lux b/source/lux.lux index a005da3da..aab80ed7e 100644 --- a/source/lux.lux +++ b/source/lux.lux @@ -22,11 +22,14 @@ (def' Text (#DataT "java.lang.String")) (export' Text) +(def' Void (#VariantT #Nil)) +(export' Void) + ## (deftype (List a) ## (| #Nil ## (#Cons (, a (List a))))) (def' List - (#AllT [#Nil "List" "a" + (#AllT [#None "List" "a" (#VariantT (#Cons [["lux;Nil" (#TupleT #Nil)] (#Cons [["lux;Cons" (#TupleT (#Cons [(#BoundT "a") (#Cons [(#AppT [(#BoundT "List") (#BoundT "a")]) @@ -34,6 +37,16 @@ #Nil])]))])) (export' List) +## (deftype (Maybe a) +## (| #None +## (#Some a))) +(def' Maybe + (#AllT [#None "Maybe" "a" + (#VariantT (#Cons [["lux;None" (#TupleT #Nil)] + (#Cons [["lux;Some" (#BoundT "a")] + #Nil])]))])) +(export' Maybe) + ## (deftype #rec Type ## (| #AnyT ## #NothingT @@ -44,47 +57,36 @@ ## (#LambdaT (, Type Type)) ## (#BoundT Text) ## (#VarT Int) -## (#AllT (, (List (, Text Type)) Text Text Type)) +## (#AllT (, (Maybe (List (, Text Type))) Text Text Type)) ## (#AppT (, Type Type)))) (def' Type (case' (#AppT [(#BoundT "Type") (#BoundT "")]) Type (case' (#AppT [List (#TupleT (#Cons [Text (#Cons [Type #Nil])]))]) TypeEnv - (#AppT [(#AllT [#Nil "Type" "" + (#AppT [(#AllT [#None "Type" "" (#VariantT (#Cons [["lux;AnyT" (#TupleT #Nil)] (#Cons [["lux;NothingT" (#TupleT #Nil)] (#Cons [["lux;DataT" Text] - (#Cons [["lux;TupleT" (#AppT [List (#AppT [(#BoundT "Type") (#BoundT "")])])] + (#Cons [["lux;TupleT" (#AppT [List Type])] (#Cons [["lux;VariantT" TypeEnv] (#Cons [["lux;RecordT" TypeEnv] (#Cons [["lux;LambdaT" (#TupleT (#Cons [Type (#Cons [Type #Nil])]))] (#Cons [["lux;BoundT" Text] (#Cons [["lux;VarT" Int] - (#Cons [["lux;AllT" (#TupleT (#Cons [TypeEnv (#Cons [Text (#Cons [Text (#Cons [Type #Nil])])])]))] + (#Cons [["lux;AllT" (#TupleT (#Cons [(#AppT [Maybe TypeEnv]) (#Cons [Text (#Cons [Text (#Cons [Type #Nil])])])]))] (#Cons [["lux;AppT" (#TupleT (#Cons [Type (#Cons [Type #Nil])]))] #Nil])])])])])])])])])])]))]) #NothingT])))) (export' Type) -## (deftype (Maybe a) -## (| #None -## (#Some a))) -(def' Maybe - (:' Type - (#AllT [#Nil "Maybe" "a" - (#VariantT (#Cons [["lux;None" (#TupleT #Nil)] - (#Cons [["lux;Some" (#BoundT "a")] - #Nil])]))]))) -(export' Maybe) - ## (deftype (Bindings k v) ## (& #counter Int ## #mappings (List (, k v)))) (def' Bindings (:' Type - (#AllT [#Nil "Bindings" "k" - (#AllT [#Nil "" "v" + (#AllT [#None "Bindings" "k" + (#AllT [#None "" "v" (#RecordT (#Cons [["lux;counter" Int] (#Cons [["lux;mappings" (#AppT [List (#TupleT (#Cons [(#BoundT "k") @@ -99,8 +101,8 @@ ## #closure (Bindings k v))) (def' Env (:' Type - (#AllT [#Nil "Env" "k" - (#AllT [#Nil "" "v" + (#AllT [#None "Env" "k" + (#AllT [#None "" "v" (#RecordT (#Cons [["lux;name" Text] (#Cons [["lux;inner-closures" Int] (#Cons [["lux;locals" (#AppT [(#AppT [Bindings (#BoundT "k")]) @@ -119,8 +121,8 @@ ## (| (#Meta (, m v)))) (def' Meta (:' Type - (#AllT [#Nil "Meta" "m" - (#AllT [#Nil "" "v" + (#AllT [#None "Meta" "m" + (#AllT [#None "" "v" (#VariantT (#Cons [["lux;Meta" (#TupleT (#Cons [(#BoundT "m") (#Cons [(#BoundT "v") #Nil])]))] @@ -186,7 +188,7 @@ Syntax'List (case' (#TupleT (#Cons [Text (#Cons [Text #Nil])])) Ident - (#AllT [#Nil "Syntax'" "w" + (#AllT [#None "Syntax'" "w" (#VariantT (#Cons [["lux;Bool" Bool] (#Cons [["lux;Int" Int] (#Cons [["lux;Real" Real] @@ -217,8 +219,8 @@ ## (#Right r))) (def' Either (:' Type - (#AllT [#Nil "_" "l" - (#AllT [#Nil "" "r" + (#AllT [#None "_" "l" + (#AllT [#None "" "r" (#VariantT (#Cons [["lux;Left" (#BoundT "l")] (#Cons [["lux;Right" (#BoundT "r")] #Nil])]))])]))) @@ -452,7 +454,7 @@ (#Cons [(#Meta [_ (#Tuple (#Cons [(#Meta [_ (#Symbol ["" arg-name])]) other-args]))]) (#Cons [body #Nil])]) (return' (#Cons [(_meta (#Form (#Cons [(_meta (#Tag ["lux" "AllT"])) - (#Cons [(_meta (#Tuple (#Cons [(_meta (#Tag ["lux" "Nil"])) + (#Cons [(_meta (#Tuple (#Cons [(_meta (#Tag ["lux" "None"])) (#Cons [(_meta (#Text "")) (#Cons [(_meta (#Text arg-name)) (#Cons [(_meta (#Form (#Cons [(_meta (#Symbol ["lux" "All'"])) @@ -760,7 +762,7 @@ ## (lambda [body arg] ## (case' arg ## (#Meta [_ (#Symbol [arg-module arg-name])]) -## (` (#AllT (list) "" (~ (_meta (#Text arg-name))) (~ (replace-ident [arg-module arg-name] +## (` (#AllT #None "" (~ (_meta (#Text arg-name))) (~ (replace-ident [arg-module arg-name] ## (` (#BoundT (~ (#Text ($ text:++ arg-module ";" arg-name))))) ## body))))))) ## body @@ -1596,7 +1598,7 @@ ## (#Symbol ["" arg])) ## args) ## body' (replace-syntax arg-replacements body)] -## (return (list (` (#AllT [#Nil (~ name') (#Tuple (list (~@ args'))) +## (return (list (` (#AllT [#None (~ name') (#Tuple (list (~@ args'))) ## (~ body')])))))) ## (def (walk-syntax type) |