]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Type/List.hs
init
[haskell/symantic.git] / Language / Symantic / Type / List.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE PatternSynonyms #-}
4 {-# LANGUAGE TypeFamilies #-}
5 {-# OPTIONS_GHC -fno-warn-orphans #-}
6 module Language.Symantic.Type.List where
7
8 import Data.Proxy
9 import Data.Type.Equality ((:~:)(Refl))
10 import Language.Symantic.Type.Root
11 import Language.Symantic.Type.Type0
12 import Language.Symantic.Type.Type1
13
14 -- * Type 'Type_List'
15 -- | The list type.
16 type Type_List = Type_Type1 (Proxy [])
17
18 pattern Type_List :: root a -> Type_List root ([] a)
19 pattern Type_List a = Type_Type1 Proxy a
20
21 instance -- Eq_Type
22 Eq_Type root =>
23 Eq_Type (Type_Type1 (Proxy []) root) where
24 eq_type (Type_Type1 _px1 a1) (Type_Type1 _px2 a2)
25 | Just Refl <- a1 `eq_type` a2
26 = Just Refl
27 eq_type _ _ = Nothing
28 instance -- Eq_Type1
29 Eq_Type1 (Type_Type1 (Proxy []) root) where
30 eq_type1 Type_Type1{} Type_Type1{}
31 = Just Refl
32 instance -- String_from_Type
33 String_from_Type root =>
34 String_from_Type (Type_List root) where
35 string_from_type (Type_Type1 _f a) =
36 "[" ++ string_from_type a ++ "]"
37
38 -- | Inject 'Type_List' within a root type.
39 type_list
40 :: Lift_Type_Root Type_List root
41 => root h_a
42 -> root ([] h_a)
43 type_list = lift_type_root . Type_Type1 (Proxy::Proxy [])