]> Git — Sourcephile - haskell/symantic.git/blob - Language/LOL/Symantic/Type/Bool.hs
init
[haskell/symantic.git] / Language / LOL / Symantic / Type / Bool.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE GADTs #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# LANGUAGE TypeFamilies #-}
6 {-# LANGUAGE UndecidableInstances #-}
7 module Language.LOL.Symantic.Type.Bool where
8
9 import Data.Maybe (isJust)
10 import Data.Type.Equality ((:~:)(Refl))
11
12 import Language.LOL.Symantic.AST
13 import Language.LOL.Symantic.Type.Common
14 import Language.LOL.Symantic.Type.Fun
15
16 -- * Type 'Type_Bool'
17
18 -- | The 'Bool' type.
19 data Type_Bool (root:: * -> *) h where
20 Type_Bool :: Type_Bool root Bool
21 type instance Root_of_Type (Type_Bool root) = root
22 type instance Error_of_Type ast (Type_Bool root) = Error_Type_Fun ast
23
24 instance -- Type_Eq
25 Type_Eq (Type_Bool root) where
26 type_eq Type_Bool Type_Bool = Just Refl
27 instance -- Eq
28 Eq (Type_Bool root h) where
29 x == y = isJust $ type_eq x y
30 instance -- Type_from AST
31 ( Type_Root_Lift Type_Bool root
32 , Error_Type_Lift (Error_Type_Fun AST) (Error_of_Type AST root)
33 -- NOTE: require UndecidableInstances.
34 ) => Type_from AST (Type_Bool root) where
35 type_from _px_ty ast k =
36 case ast of
37 AST "Bool" asts ->
38 case asts of
39 [] -> k $ type_root_lift Type_Bool
40 _ -> Left $ Just $ error_type_lift $
41 Error_Type_Fun_Wrong_number_of_arguments 0 ast
42 _ -> Left Nothing
43 instance -- String_from_Type
44 String_from_Type (Type_Bool root) where
45 string_from_type Type_Bool = "Bool"
46 instance -- Show
47 Show (Type_Bool root h) where
48 show = string_from_type
49
50 -- | Convenient alias to include a 'Type_Bool' within a type.
51 type_bool :: Type_Root_Lift Type_Bool root => root Bool
52 type_bool = type_root_lift Type_Bool
53
54 -- * Type 'Type_Fun_Bool'
55 -- | Convenient alias.
56 type Type_Fun_Bool lam = Type_Root (Type_Cons (Type_Fun lam) Type_Bool)