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