{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} module Language.Symantic.Type.Tuple where import Data.Maybe (isJust) import Data.Type.Equality ((:~:)(Refl)) import Language.Symantic.Type.Common import Language.Symantic.Type.Fun import Language.Symantic.Type.Bool import Language.Symantic.Type.Var -- * Type 'Type_Tuple2' -- | The 'Tuple' type. data Type_Tuple2 root h where Type_Tuple2 :: root h_a -> root h_b -> Type_Tuple2 root (h_a, h_b) type instance Root_of_Type (Type_Tuple2 root) = root type instance Error_of_Type ast (Type_Tuple2 root) = No_Error_Type instance -- Eq_Type Eq_Type root => Eq_Type (Type_Tuple2 root) where eq_type (Type_Tuple2 a1 b1) (Type_Tuple2 a2 b2) | Just Refl <- a1 `eq_type` a2 , Just Refl <- b1 `eq_type` b2 = Just Refl eq_type _ _ = Nothing instance -- Eq Eq_Type root => Eq (Type_Tuple2 root h) where x == y = isJust $ eq_type x y instance -- String_from_Type String_from_Type root => String_from_Type (Type_Tuple2 root) where string_from_type (Type_Tuple2 a b) = "Tuple (" ++ string_from_type a ++ ", " ++ string_from_type b ++ ")" instance -- Show String_from_Type root => Show (Type_Tuple2 root h) where show = string_from_type -- | Convenient alias to include a 'Type_Tuple2' within a type. type_tuple2 :: Type_Root_Lift Type_Tuple2 root => root h_a -> root h_b -> root (h_a, h_b) type_tuple2 a b = type_root_lift (Type_Tuple2 a b) -- * Type 'Type_Fun_Bool_Tuple2' -- | Convenient alias. type Type_Fun_Bool_Tuple2 lam = Type_Root (Type_Alt Type_Var (Type_Alt (Type_Fun lam) (Type_Alt Type_Bool Type_Tuple2)))