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 qualified Data.MonoTraversable as MT
14 import Language.Symantic.Type.Root
15 import Language.Symantic.Type.Type0
16 import Language.Symantic.Type.Type1
17 import Language.Symantic.Type.Type2
18 import Language.Symantic.Type.Constraint
19 import Language.Symantic.Type.Family
21 -- * Type 'Type_Either'
22 -- | The 'Either' type.
23 type Type_Either = Type2 (Proxy Either)
27 -> Type_Either root (Either l r)
28 pattern Type_Either l r
31 instance Type1_Unlift Type_Either where
32 type1_unlift (Type2 px a b) k =
33 k ( Type1 (Proxy::Proxy (Either a)) b
34 , Type1_Lift (\(Type1 _ b') -> Type2 px a b')
36 instance Type0_Eq root => Type1_Eq (Type_Either root) where
37 type1_eq (Type2 _ a1 _b1) (Type2 _ a2 _b2)
38 | Just Refl <- type0_eq a1 a2
40 type1_eq _ _ = Nothing
42 Type0_Constraint Eq root =>
43 Type0_Constraint Eq (Type_Either root) where
44 type0_constraint c (Type2 _ l r)
45 | Just Dict <- type0_constraint c l
46 , Just Dict <- type0_constraint c r
48 type0_constraint _c _ = Nothing
50 Type0_Constraint Ord root =>
51 Type0_Constraint Ord (Type_Either root) where
52 type0_constraint c (Type2 _ l r)
53 | Just Dict <- type0_constraint c l
54 , Just Dict <- type0_constraint c r
56 type0_constraint _c _ = Nothing
57 instance Type0_Constraint Num (Type_Either root)
58 instance Type0_Constraint Integral (Type_Either root)
59 instance Type0_Constraint MT.MonoFunctor (Type_Either root) where
60 type0_constraint _c Type2{} = Just Dict
61 instance Type1_Constraint Functor (Type_Either root) where
62 type1_constraint _c Type2{} = Just Dict
63 instance Type1_Constraint Applicative (Type_Either root) where
64 type1_constraint _c Type2{} = Just Dict
65 instance Type1_Constraint Traversable (Type_Either root) where
66 type1_constraint _c Type2{} = Just Dict
67 instance Type1_Constraint Monad (Type_Either root) where
68 type1_constraint _c Type2{} = Just Dict
69 instance Type0_Family Type_Family_MonoElement (Type_Either root) where
70 type0_family _at (Type2 _px _l r) = Just r
73 Type0_Eq (Type_Either root) where
77 | Just Refl <- l1 `type0_eq` l2
78 , Just Refl <- r1 `type0_eq` r2
80 type0_eq _ _ = Nothing
81 instance -- String_from_Type
82 String_from_Type root =>
83 String_from_Type (Type_Either root) where
84 string_from_type (Type2 _ l r) =
86 ++ " (" ++ string_from_type l ++ ")"
87 ++ " (" ++ string_from_type r ++ ")"
89 -- | Inject 'Type_Either' within a root type.
91 :: Type_Root_Lift Type_Either root
92 => root h_l -> root h_r -> root (Either h_l h_r)