diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-07-26 23:02:09 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-07-26 23:02:09 +0200 |
commit | 342c213f3caddd64db0eac5ae146912e00378371 (patch) | |
tree | 80f55eb7ccabf24ea0787db428595cdbf6caffe0 /backend/CC/Backend | |
parent | 494b764274be4db53499fa4eb7decacb93c7bbe9 (diff) |
WIP refactor and union types, type variables
Diffstat (limited to 'backend/CC/Backend')
-rw-r--r-- | backend/CC/Backend/Dumb.hs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/backend/CC/Backend/Dumb.hs b/backend/CC/Backend/Dumb.hs index 3210dab..822fb84 100644 --- a/backend/CC/Backend/Dumb.hs +++ b/backend/CC/Backend/Dumb.hs @@ -7,10 +7,20 @@ import CC.Context builtins :: Builtins -builtins = Builtins . Map.fromList $ - [ ("print", TFun TInt (TTup [])) - , ("fst", TFun (TTup [TyVar 1, TyVar 2]) (TyVar 1)) - , ("snd", TFun (TTup [TyVar 1, TyVar 2]) (TyVar 2)) - , ("_add", TFun TInt (TFun TInt TInt)) - , ("_sub", TFun TInt (TFun TInt TInt)) - , ("_mul", TFun TInt (TFun TInt TInt)) ] +builtins = + let values = Map.fromList + [ ("print", TInt ==> TTup []) + , ("fst", TTup [t1, t2] ==> t1) + , ("snd", TTup [t1, t2] ==> t2) + , ("_add", TInt ==> TInt ==> TInt) + , ("_sub", TInt ==> TInt ==> TInt) + , ("_mul", TInt ==> TInt ==> TInt) ] + prelude = "type Nil = ()\n\ + \type Cons a = (a, List a)\n\ + \alias List a = { Nil | Cons a }\n" + in Builtins values prelude + where + t1 = TyVar Instantiable 1 + t2 = TyVar Instantiable 2 + infixr ==> + (==>) = TFun |