Types.hs 634 B

123456789101112131415161718192021222324
  1. module Gidl.Types
  2. ( module Gidl.Types.AST
  3. , module Gidl.Types.Base
  4. , lookupTypeName
  5. , insertType
  6. ) where
  7. import Gidl.Types.AST
  8. import Gidl.Types.Base
  9. lookupTypeName :: TypeName -> TypeEnv -> Maybe Type
  10. lookupTypeName tn te =
  11. case aux te of
  12. Just a -> Just a
  13. Nothing -> case aux baseTypeEnv of
  14. Just a -> Just a
  15. Nothing -> Nothing
  16. where
  17. aux (TypeEnv e) = lookup tn e
  18. insertType :: TypeName -> Type -> TypeEnv -> TypeEnv
  19. insertType tn t e@(TypeEnv te) = case lookupTypeName tn e of
  20. Nothing -> TypeEnv ((tn,t):te)
  21. Just _ -> error ("insertType invariant broken: type " ++ tn ++ " already exists")