{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} module Language.LOL.Symantic.Type.Int where import Data.Maybe (isJust) import Data.Type.Equality ((:~:)(Refl)) import Language.LOL.Symantic.AST import Language.LOL.Symantic.Type.Common import Language.LOL.Symantic.Type.Fun import Language.LOL.Symantic.Type.Bool import Language.LOL.Symantic.Type.Var -- * Type 'Type_Int' -- | The 'Int' type. data Type_Int (root:: * -> *) h where Type_Int :: Type_Int root Int type instance Root_of_Type (Type_Int root) = root type instance Error_of_Type ast (Type_Int root) = () instance -- Type_Eq Type_Eq (Type_Int root) where type_eq Type_Int Type_Int = Just Refl instance -- Eq Eq (Type_Int root h) where x == y = isJust $ x `type_eq` y instance -- Type_from AST ( Type_Root_Lift Type_Int root , Error_Type_Lift (Error_Type AST) (Error_of_Type AST root) , Implicit_HBool (Is_Last_Type (Type_Int root) root) ) => Type_from AST (Type_Int root) where type_from px_ty ast k = case ast of AST "Int" asts -> case asts of [] -> k $ type_root_lift Type_Int _ -> Left $ error_type_lift $ Error_Type_Wrong_number_of_arguments ast 0 _ -> Left $ error_type_unsupported px_ty ast instance -- String_from_Type String_from_Type (Type_Int root) where string_from_type Type_Int = "Int" instance -- Show Show (Type_Int root h) where show = string_from_type -- | Convenient alias to include a 'Type_Int' within a type. type_int :: Type_Root_Lift Type_Int root => root Int type_int = type_root_lift Type_Int -- * Type 'Type_Fun_Int' -- | Convenient alias. type Type_Fun_Int lam = Type_Root (Type_Alt Type_Var (Type_Alt (Type_Fun lam) Type_Int)) -- * Type 'Type_Fun_Bool_Int' -- | Convenient alias. type Type_Fun_Bool_Int lam = Type_Root (Type_Alt Type_Var (Type_Alt (Type_Fun lam) (Type_Alt Type_Bool Type_Int)))