1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE PatternSynonyms #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeFamilies #-}
7 {-# OPTIONS_GHC -fno-warn-orphans #-}
8 module Language.Symantic.Type.Either where
11 import Data.Type.Equality ((:~:)(Refl))
12 import Language.Symantic.Type.Root
13 import Language.Symantic.Type.Type0
14 import Language.Symantic.Type.Type1
15 import Language.Symantic.Type.Type2
17 -- * Type 'Type_Either'
18 -- | The 'Either' type.
19 type Type_Either = Type_Type2 (Proxy Either)
21 type instance Constraint2_of (Proxy Either)
23 instance Unlift_Type1 (Type_Type2 (Proxy Either)) where
24 unlift_type1 (Type_Type2 px a b) k =
25 k ( Type_Type1 (Proxy::Proxy (Either a)) b
26 , Lift_Type1 (\(Type_Type1 _ b') -> Type_Type2 px a b')
28 instance Constraint_Type1 Applicative (Type_Either root) where
29 constraint_type1 _c Type_Type2{} = Just Dict
32 instance Constraint_Type1 Functor (Type_Type1 (Proxy ((,) fst)) root) where
33 constraint_type1 _c Type_Type1{} = Just Dict
34 instance Constraint_Type1 Functor (Type_Tuple2 root) where
35 instance Constraint_Type1 Applicative (Type_Type1 (Proxy ((,) fst)) root)
40 -> Type_Either root (Either l r)
41 pattern Type_Either l r
42 = Type_Type2 Proxy l r
46 Eq_Type (Type_Either root) where
50 | Just Refl <- l1 `eq_type` l2
51 , Just Refl <- r1 `eq_type` r2
54 instance -- String_from_Type
55 String_from_Type root =>
56 String_from_Type (Type_Either root) where
57 string_from_type (Type_Type2 _ l r) =
59 ++ " (" ++ string_from_type l ++ ")"
60 ++ " (" ++ string_from_type r ++ ")"
62 -- | Inject 'Type_Either' within a root type.
64 :: forall root h_l h_r.
65 Lift_Type_Root Type_Either root
68 -> root (Either h_l h_r)
69 type_either l r = lift_type_root
71 ::Type_Either root (Either h_l h_r))