{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} module Language.Symantic.Type.Maybe where import Data.Maybe (isJust) import Data.Type.Equality ((:~:)(Refl)) import Language.Symantic.Type.Common -- * Type 'Type_Maybe' -- | The 'Maybe' type. data Type_Maybe root h where Type_Maybe :: root h_a -> Type_Maybe root (Maybe h_a) type instance Root_of_Type (Type_Maybe root) = root type instance Error_of_Type ast (Type_Maybe root) = No_Error_Type instance -- Type_Eq Type_Eq root => Type_Eq (Type_Maybe root) where type_eq (Type_Maybe a1) (Type_Maybe a2) | Just Refl <- a1 `type_eq` a2 = Just Refl type_eq _ _ = Nothing instance -- Eq Type_Eq root => Eq (Type_Maybe root h) where x == y = isJust $ type_eq x y instance -- String_from_Type String_from_Type root => String_from_Type (Type_Maybe root) where string_from_type (Type_Maybe a) = "Maybe (" ++ string_from_type a ++ ")" instance -- Show String_from_Type root => Show (Type_Maybe root h) where show = string_from_type -- | Convenient alias to include a 'Type_Maybe' within a type. type_maybe :: Type_Root_Lift Type_Maybe root => root h_a -> root (Maybe h_a) type_maybe a = type_root_lift (Type_Maybe a)