{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} module Language.LOL.Symantic.Type.Bool 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 -- * Type 'Type_Bool' -- | The 'Bool' type. data Type_Bool (root:: * -> *) h where Type_Bool :: Type_Bool root Bool type instance Root_of_Type (Type_Bool root) = root type instance Error_of_Type ast (Type_Bool root) = Error_Type_Fun ast instance -- Type_Eq Type_Eq (Type_Bool root) where type_eq Type_Bool Type_Bool = Just Refl instance -- Eq Eq (Type_Bool root h) where x == y = isJust $ type_eq x y instance -- Type_from AST ( Type_Root_Lift Type_Bool 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. ) => Type_from AST (Type_Bool root) where type_from _px_ty ast k = case ast of AST "Bool" asts -> case asts of [] -> k $ type_root_lift Type_Bool _ -> Left $ error_type_lift $ Error_Type_Fun_Wrong_number_of_arguments 0 ast _ -> Left $ error_type_lift $ Error_Type_Unsupported ast instance -- String_from_Type String_from_Type (Type_Bool root) where string_from_type Type_Bool = "Bool" instance -- Show Show (Type_Bool root h) where show = string_from_type -- | Convenient alias to include a 'Type_Bool' within a type. type_bool :: Type_Root_Lift Type_Bool root => root Bool type_bool = type_root_lift Type_Bool -- * Type 'Type_Fun_Bool' -- | Convenient alias. type Type_Fun_Bool lam = Type_Root (Type_Cons (Type_Fun lam) Type_Bool)