1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeFamilies #-}
7 {-# LANGUAGE UndecidableInstances #-}
8 module Language.LOL.Symantic.Type.Maybe where
10 import Data.Maybe (isJust)
11 import Data.Type.Equality ((:~:)(Refl))
14 import Language.LOL.Symantic.AST
15 import Language.LOL.Symantic.Type.Common
16 import Language.LOL.Symantic.Type.Fun
17 import Language.LOL.Symantic.Type.Bool
18 import Language.LOL.Symantic.Type.Var
20 -- * Type 'Type_Maybe'
21 -- | The 'Maybe' type.
22 data Type_Maybe root h where
23 Type_Maybe :: root h_a
24 -> Type_Maybe root (Maybe h_a)
26 type instance Root_of_Type (Type_Maybe root) = root
27 type instance Error_of_Type ast (Type_Maybe root) = ()
31 Type_Eq (Type_Maybe root) where
32 type_eq (Type_Maybe a1) (Type_Maybe a2)
33 | Just Refl <- a1 `type_eq` a2
38 Eq (Type_Maybe root h) where
39 x == y = isJust $ type_eq x y
40 instance -- Type_from AST
43 , Type_Root_Lift Type_Maybe root
44 , Error_Type_Lift (Error_Type AST) (Error_of_Type AST root)
45 , Error_Type_Unlift (Error_Type AST) (Error_of_Type AST root)
46 , Root_of_Type root ~ root
47 , Implicit_HBool (Is_Last_Type (Type_Maybe root) root)
48 ) => Type_from AST (Type_Maybe root) where
49 type_from px_ty ast k =
54 type_from (Proxy::Proxy root) ast_a $ \(ty_a::root h_a) ->
55 k (type_root_lift $ Type_Maybe ty_a
57 _ -> Left $ error_type_lift $
58 Error_Type_Wrong_number_of_arguments ast 1
59 _ -> Left $ error_type_unsupported px_ty ast
60 instance -- String_from_Type
61 String_from_Type root =>
62 String_from_Type (Type_Maybe root) where
63 string_from_type (Type_Maybe a) =
64 "Maybe (" ++ string_from_type a ++ ")"
66 String_from_Type root =>
67 Show (Type_Maybe root h) where
68 show = string_from_type
70 -- | Convenient alias to include a 'Type_Maybe' within a type.
72 :: Type_Root_Lift Type_Maybe root
75 type_maybe a = type_root_lift (Type_Maybe a)
77 -- * Type 'Type_Fun_Bool_Maybe'
78 -- | Convenient alias.
79 type Type_Fun_Bool_Maybe lam
80 = Type_Root (Type_Alt Type_Var
81 (Type_Alt (Type_Fun lam)