{-# 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 -- * 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) = Error_Type_Fun ast 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 $ type_eq x y instance -- Type_from AST ( Type_Root_Lift Type_Int root , Error_Type_Lift (Error_Type AST) (Error_of_Type AST root) -- NOTE: require UndecidableInstances. , Error_Type_Lift (Error_Type_Fun AST) (Error_of_Type AST root) -- NOTE: require UndecidableInstances. , 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_Fun_Wrong_number_of_arguments 0 ast _ -> Left $ case hbool :: HBool (Is_Last_Type (Type_Int root) root) of HTrue -> error_type_lift $ Error_Type_Unsupported_from_root ast HFalse -> error_type_lift $ Error_Type_Unsupported 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_Cons (Type_Fun lam) Type_Int) -- * Type 'Type_Fun_Bool_Int' -- | Convenient alias. type Type_Fun_Bool_Int lam = Type_Root (Type_Cons (Type_Fun lam) (Type_Cons Type_Bool Type_Int))