Unification part works (probably). Have a hard time understanding it.

This commit is contained in:
sebastianselander 2023-02-17 18:42:50 +01:00
parent 764faa582b
commit f188cffb8d
7 changed files with 167 additions and 197 deletions

View file

@ -1,21 +1,21 @@
{-# LANGUAGE LambdaCase #-}
module TypeChecker.TypeCheckerIr ( TProgram(..)
, TBind(..)
, TExp(..)
, RProgram(..)
, RBind(..)
, RExp(..)
, Type(..)
, Const(..)
, Ident(..)
)
where
module TypeChecker.TypeCheckerIr (
TProgram (..),
TBind (..),
TExp (..),
RProgram (..),
RBind (..),
RExp (..),
Type (..),
Const (..),
Ident (..),
) where
import Renamer.RenamerIr
import Grammar.Print
import Grammar.Print
import Renamer.RenamerIr
data TProgram = TProgram [TBind]
newtype TProgram = TProgram [TBind]
deriving (Eq, Show, Read, Ord)
data TBind = TBind Ident Type TExp
@ -50,21 +50,25 @@ instance Print TBind where
instance Print TExp where
prt i = \case
TAnn e t -> prPrec i 2 $ concatD
[ prt 0 e
, doc (showString ":")
, prt 1 t
]
TBound _ u t -> prPrec i 3 $ concatD [ prt 0 u ]
TFree u t -> prPrec i 3 $ concatD [ prt 0 u ]
TAnn e t ->
prPrec i 2 $
concatD
[ prt 0 e
, doc (showString ":")
, prt 1 t
]
TBound _ u t -> prPrec i 3 $ concatD [prt 0 u]
TFree u t -> prPrec i 3 $ concatD [prt 0 u]
TConst c _ -> prPrec i 3 (concatD [prt 0 c])
TApp e e1 t -> prPrec i 2 $ concatD [ prt 2 e , prt 3 e1 ]
TAdd e e1 t -> prPrec i 1 $ concatD [ prt 1 e , doc (showString "+") , prt 2 e1 ]
TAbs _ u e t -> prPrec i 0 $ concatD
[ doc (showString "(")
, doc (showString "λ")
, prt 0 u
, doc (showString ".")
, prt 0 e
, doc (showString ")")
]
TApp e e1 t -> prPrec i 2 $ concatD [prt 2 e, prt 3 e1]
TAdd e e1 t -> prPrec i 1 $ concatD [prt 1 e, doc (showString "+"), prt 2 e1]
TAbs _ u e t ->
prPrec i 0 $
concatD
[ doc (showString "(")
, doc (showString "λ")
, prt 0 u
, doc (showString ".")
, prt 0 e
, doc (showString ")")
]