1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE MultiParamTypeClasses #-}
5 {-# LANGUAGE OverloadedStrings #-}
6 {-# LANGUAGE PatternSynonyms #-}
7 {-# LANGUAGE ScopedTypeVariables #-}
8 {-# LANGUAGE TypeFamilies #-}
9 {-# OPTIONS_GHC -fno-warn-orphans #-}
10 module Language.Symantic.Type.Map where
12 import Data.Map.Strict as Map
13 import qualified Data.MonoTraversable as MT
15 import Data.Type.Equality ((:~:)(Refl))
17 import Language.Symantic.Type.Root
18 import Language.Symantic.Type.Type0
19 import Language.Symantic.Type.Type1
20 import Language.Symantic.Type.Type2
24 type Type_Map = Type_Type2 (Proxy Map)
28 -> Type_Type2 (Proxy Map) root (Map k a)
30 = Type_Type2 Proxy k a
32 instance Unlift_Type1 Type_Map where
33 unlift_type1 (Type_Type2 px a b) k =
34 k ( Type_Type1 (Proxy::Proxy (Map a)) b
35 , Lift_Type1 (\(Type_Type1 _ b') -> Type_Type2 px a b')
38 Constraint_Type Eq root =>
39 Constraint_Type Eq (Type_Map root) where
40 constraint_type c (Type_Type2 _ k a)
41 | Just Dict <- constraint_type c k
42 , Just Dict <- constraint_type c a
44 constraint_type _c _ = Nothing
46 Constraint_Type Ord root =>
47 Constraint_Type Ord (Type_Map root) where
48 constraint_type c (Type_Type2 _ k a)
49 | Just Dict <- constraint_type c k
50 , Just Dict <- constraint_type c a
52 constraint_type _c _ = Nothing
54 Constraint_Type Ord root =>
55 Constraint_Type Monoid (Type_Map root) where
56 constraint_type _c (Type_Type2 _ k _a)
57 | Just Dict <- constraint_type (Proxy::Proxy Ord) k
59 constraint_type _c _ = Nothing
60 instance Constraint_Type Num (Type_Map root)
61 instance Constraint_Type Integral (Type_Map root)
62 instance Constraint_Type MT.MonoFunctor (Type_Map root) where
63 constraint_type _c Type_Type2{} = Just Dict
64 instance Constraint_Type1 Functor (Type_Map root) where
65 constraint_type1 _c Type_Type2{} = Just Dict
66 instance Constraint_Type1 Traversable (Type_Map root) where
67 constraint_type1 _c Type_Type2{} = Just Dict
68 instance Constraint_Type1 Foldable (Type_Map root) where
69 constraint_type1 _c Type_Type2{} = Just Dict
72 Eq_Type (Type_Map root) where
73 eq_type (Type_Type2 _px1 k1 a1) (Type_Type2 _px2 k2 a2)
74 | Just Refl <- k1 `eq_type` k2
75 , Just Refl <- a1 `eq_type` a2
80 Eq_Type1 (Type_Map root) where
81 eq_type1 (Type_Type2 _px1 k1 _a1) (Type_Type2 _px2 k2 _a2)
82 | Just Refl <- k1 `eq_type` k2
84 eq_type1 _ _ = Nothing
85 instance -- String_from_Type
86 String_from_Type root =>
87 String_from_Type (Type_Map root) where
88 string_from_type (Type_Type2 _ k a) =
89 "Map (" ++ string_from_type k ++ ")"
90 ++ " (" ++ string_from_type a ++ ")"
92 -- | Inject 'Type_Map' within a root type.
94 :: forall root h_k h_a.
95 (Lift_Type_Root Type_Map root)
96 => root h_k -> root h_a