{-# 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 -- * Type 'Type_Tuple2' -- | The (,) 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 :: Lift_Type_Root Type_Tuple2 root => root h_a -> root h_b -> root (h_a, h_b) type_tuple2 a b = lift_type_root (Type_Tuple2 a b)