From 342c213f3caddd64db0eac5ae146912e00378371 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 26 Jul 2020 23:02:09 +0200 Subject: WIP refactor and union types, type variables --- backend/CC/Backend/Dumb.hs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'backend/CC/Backend') 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 -- cgit v1.2.3-70-g09d2