1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE PatternSynonyms #-}
5 {-# LANGUAGE TypeFamilies #-}
6 {-# OPTIONS_GHC -fno-warn-orphans #-}
7 module Language.Symantic.Type.Maybe where
10 import Data.Type.Equality ((:~:)(Refl))
11 import Language.Symantic.Type.Root
12 import Language.Symantic.Type.Type0
13 import Language.Symantic.Type.Type1
15 -- * Type 'Type_Maybe'
16 -- | The 'Maybe' type.
17 type Type_Maybe = Type_Type1 (Proxy Maybe)
19 pattern Type_Maybe :: root a -> Type_Maybe root (Maybe a)
20 pattern Type_Maybe a = Type_Type1 Proxy a
22 instance Constraint_Type Eq root => Constraint_Type Eq (Type_Maybe root) where
23 constraint_type c (Type_Type1 _ a)
24 | Just Dict <- constraint_type c a
26 constraint_type _c _ = Nothing
27 instance Constraint_Type Ord root => Constraint_Type Ord (Type_Maybe root) where
28 constraint_type c (Type_Type1 _ a)
29 | Just Dict <- constraint_type c a
31 constraint_type _c _ = Nothing
32 instance Constraint_Type Monoid root => Constraint_Type Monoid (Type_Maybe root) where
33 constraint_type c (Type_Type1 _ a)
34 | Just Dict <- constraint_type c a
36 constraint_type _c _ = Nothing
37 instance Constraint_Type Num (Type_Maybe root)
38 instance Constraint_Type Integral (Type_Maybe root)
39 instance Constraint_Type1 Functor (Type_Maybe root) where
40 constraint_type1 _c (Type_Type1 _ _) = Just Dict
41 instance Constraint_Type1 Applicative (Type_Maybe root) where
42 constraint_type1 _c (Type_Type1 _ _) = Just Dict
43 instance Constraint_Type1 Foldable (Type_Maybe root) where
44 constraint_type1 _c (Type_Type1 _ _) = Just Dict
45 instance Constraint_Type1 Traversable (Type_Maybe root) where
46 constraint_type1 _c (Type_Type1 _ _) = Just Dict
47 instance Constraint_Type1 Monad (Type_Maybe root) where
48 constraint_type1 _c Type_Type1{} = Just Dict
51 Eq_Type (Type_Maybe root) where
52 eq_type (Type_Type1 _px1 a1) (Type_Type1 _px2 a2)
53 | Just Refl <- a1 `eq_type` a2
57 Eq_Type1 (Type_Maybe root) where
58 eq_type1 Type_Type1{} Type_Type1{}
60 instance -- String_from_Type
61 String_from_Type root =>
62 String_from_Type (Type_Maybe root) where
63 string_from_type (Type_Type1 _f a) =
64 "Maybe" ++ " (" ++ string_from_type a ++ ")"
66 -- | Inject 'Type_Maybe' within a root type.
68 :: Lift_Type_Root Type_Maybe root
71 type_maybe = lift_type_root . Type_Type1 (Proxy::Proxy Maybe)