{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Language.Symantic.Type.Either where import Data.Proxy import Data.Type.Equality ((:~:)(Refl)) import Language.Symantic.Type.Root import Language.Symantic.Type.Type0 import Language.Symantic.Type.Type1 import Language.Symantic.Type.Type2 -- * Type 'Type_Either' -- | The 'Either' type. type Type_Either = Type_Type2 (Proxy Either) type instance Constraint2_of (Proxy Either) = Constraint2_Empty instance Unlift_Type1 (Type_Type2 (Proxy Either)) where unlift_type1 (Type_Type2 px a b) k = k ( Type_Type1 (Proxy::Proxy (Either a)) b , Lift_Type1 (\(Type_Type1 _ b') -> Type_Type2 px a b') ) instance Constraint_Type1 Applicative (Type_Either root) where constraint_type1 _c Type_Type2{} = Just Dict {- instance Constraint_Type1 Functor (Type_Type1 (Proxy ((,) fst)) root) where constraint_type1 _c Type_Type1{} = Just Dict instance Constraint_Type1 Functor (Type_Tuple2 root) where instance Constraint_Type1 Applicative (Type_Type1 (Proxy ((,) fst)) root) -} pattern Type_Either :: root l -> root r -> Type_Either root (Either l r) pattern Type_Either l r = Type_Type2 Proxy l r instance -- Eq_Type Eq_Type root => Eq_Type (Type_Either root) where eq_type (Type_Type2 _ l1 r1) (Type_Type2 _ l2 r2) | Just Refl <- l1 `eq_type` l2 , Just Refl <- r1 `eq_type` r2 = Just Refl eq_type _ _ = Nothing instance -- String_from_Type String_from_Type root => String_from_Type (Type_Either root) where string_from_type (Type_Type2 _ l r) = "Either" ++ " (" ++ string_from_type l ++ ")" ++ " (" ++ string_from_type r ++ ")" -- | Inject 'Type_Either' within a root type. type_either :: forall root h_l h_r. Lift_Type_Root Type_Either root => root h_l -> root h_r -> root (Either h_l h_r) type_either l r = lift_type_root (Type_Either l r ::Type_Either root (Either h_l h_r))