]> 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 GADTs #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeFamilies #-}
7 module Language.Symantic.Type.Maybe where
8
9 import Data.Maybe (isJust)
10 import Data.Type.Equality ((:~:)(Refl))
11
12 import Language.Symantic.Type.Common
13 import Language.Symantic.Type.Fun
14 import Language.Symantic.Type.Bool
15 import Language.Symantic.Type.Var
16
17 -- * Type 'Type_Maybe'
18 -- | The 'Maybe' type.
19 data Type_Maybe root h where
20 Type_Maybe :: root h_a
21 -> Type_Maybe root (Maybe h_a)
22
23 type instance Root_of_Type (Type_Maybe root) = root
24 type instance Error_of_Type ast (Type_Maybe root) = No_Error_Type
25
26 instance -- Type_Eq
27 Type_Eq root =>
28 Type_Eq (Type_Maybe root) where
29 type_eq (Type_Maybe a1) (Type_Maybe a2)
30 | Just Refl <- a1 `type_eq` a2
31 = Just Refl
32 type_eq _ _ = Nothing
33 instance -- Eq
34 Type_Eq root =>
35 Eq (Type_Maybe root h) where
36 x == y = isJust $ type_eq x y
37 instance -- String_from_Type
38 String_from_Type root =>
39 String_from_Type (Type_Maybe root) where
40 string_from_type (Type_Maybe a) =
41 "Maybe (" ++ string_from_type a ++ ")"
42 instance -- Show
43 String_from_Type root =>
44 Show (Type_Maybe root h) where
45 show = string_from_type
46
47 -- | Convenient alias to include a 'Type_Maybe' within a type.
48 type_maybe
49 :: Type_Root_Lift Type_Maybe root
50 => root h_a
51 -> root (Maybe h_a)
52 type_maybe a = type_root_lift (Type_Maybe a)
53
54 -- * Type 'Type_Fun_Bool_Maybe'
55 -- | Convenient alias.
56 type Type_Fun_Bool_Maybe lam
57 = Type_Root (Type_Alt Type_Var
58 (Type_Alt (Type_Fun lam)
59 (Type_Alt Type_Bool
60 Type_Maybe)))