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.Tuple 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_Tuple2'
19 type Type_Tuple2 = Type_Type2 (Proxy (,))
23 -> Type_Tuple2 root ((,) a b)
24 pattern Type_Tuple2 a b
25 = Type_Type2 Proxy a b
27 instance Unlift_Type1 Type_Tuple2 where
28 unlift_type1 (Type_Type2 px a b) k =
29 k ( Type_Type1 (Proxy::Proxy ((,) a)) b
30 , Lift_Type1 (\(Type_Type1 _ b') -> Type_Type2 px a b')
33 Constraint_Type Eq root =>
34 Constraint_Type Eq (Type_Tuple2 root) where
35 constraint_type c (Type_Type2 _ a b)
36 | Just Dict <- constraint_type c a
37 , Just Dict <- constraint_type c b
39 constraint_type _c _ = Nothing
41 Constraint_Type Ord root =>
42 Constraint_Type Ord (Type_Tuple2 root) where
43 constraint_type c (Type_Type2 _ a b)
44 | Just Dict <- constraint_type c a
45 , Just Dict <- constraint_type c b
47 constraint_type _c _ = Nothing
49 Constraint_Type Monoid root =>
50 Constraint_Type Monoid (Type_Tuple2 root) where
51 constraint_type c (Type_Type2 _ a b)
52 | Just Dict <- constraint_type c a
53 , Just Dict <- constraint_type c b
55 constraint_type _c _ = Nothing
56 instance Constraint_Type Num (Type_Tuple2 root)
57 instance Constraint_Type Integral (Type_Tuple2 root)
58 instance Constraint_Type1 Functor (Type_Tuple2 root) where
59 constraint_type1 _c Type_Type2{} = Just Dict
61 Constraint_Type Monoid root =>
62 Constraint_Type1 Applicative (Type_Tuple2 root) where
63 constraint_type1 _c (Type_Type2 _ a _b)
64 | Just Dict <- constraint_type (Proxy::Proxy Monoid) a
66 constraint_type1 _c _ = Nothing
67 instance Constraint_Type1 Foldable (Type_Tuple2 root) where
68 constraint_type1 _c Type_Type2{} = Just Dict
69 instance Constraint_Type1 Traversable (Type_Tuple2 root) where
70 constraint_type1 _c Type_Type2{} = Just Dict
73 Eq_Type (Type_Tuple2 root) where
74 eq_type (Type_Type2 _px1 a1 b1) (Type_Type2 _px2 a2 b2)
75 | Just Refl <- a1 `eq_type` a2
76 , Just Refl <- b1 `eq_type` b2
81 Eq_Type1 (Type_Tuple2 root) where
82 eq_type1 (Type_Type2 _px1 a1 _b1) (Type_Type2 _px2 a2 _b2)
83 | Just Refl <- a1 `eq_type` a2
85 eq_type1 _ _ = Nothing
86 instance -- String_from_Type
87 String_from_Type root =>
88 String_from_Type (Type_Tuple2 root) where
89 string_from_type (Type_Type2 _ a b) =
90 "(" ++ string_from_type a ++
91 ", " ++ string_from_type b ++ ")"
93 -- | Inject 'Type_Tuple2' within a root type.
95 :: forall root h_a h_b.
96 Lift_Type_Root Type_Tuple2 root
100 type_tuple2 a b = lift_type_root
102 ::Type_Tuple2 root (h_a, h_b))