]> 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 ScopedTypeVariables #-}
6 {-# LANGUAGE TypeFamilies #-}
7 {-# LANGUAGE UndecidableInstances #-}
8 module Language.LOL.Symantic.Type.Bool where
9
10 import Data.Maybe (isJust)
11 import Data.Type.Equality ((:~:)(Refl))
12
13 import Language.LOL.Symantic.AST
14 import Language.LOL.Symantic.Type.Common
15 import Language.LOL.Symantic.Type.Fun
16 import Language.LOL.Symantic.Type.Var
17
18 -- * Type 'Type_Bool'
19 -- | The 'Bool' type.
20 data Type_Bool (root:: * -> *) h where
21 Type_Bool :: Type_Bool root Bool
22 type instance Root_of_Type (Type_Bool root) = root
23 type instance Error_of_Type ast (Type_Bool root) = ()
24
25 instance -- Type_Eq
26 Type_Eq (Type_Bool root) where
27 type_eq Type_Bool Type_Bool = Just Refl
28 instance -- Eq
29 Eq (Type_Bool root h) where
30 x == y = isJust $ x `type_eq` y
31 instance -- Type_from AST
32 ( Type_Root_Lift Type_Bool root
33 , Error_Type_Lift (Error_Type AST) (Error_of_Type AST root)
34 , Implicit_HBool (Is_Last_Type (Type_Bool root) root)
35 ) => Type_from AST (Type_Bool root) where
36 type_from px_ty ast k =
37 case ast of
38 AST "Bool" asts ->
39 case asts of
40 [] -> k $ type_root_lift Type_Bool
41 _ -> Left $ error_type_lift $
42 Error_Type_Wrong_number_of_arguments ast 0
43 _ -> Left $ error_type_unsupported px_ty ast
44 instance -- String_from_Type
45 String_from_Type (Type_Bool root) where
46 string_from_type Type_Bool = "Bool"
47 instance -- Show
48 Show (Type_Bool root h) where
49 show = string_from_type
50
51 -- | Convenient alias to include a 'Type_Bool' within a type.
52 type_bool :: Type_Root_Lift Type_Bool root => root Bool
53 type_bool = type_root_lift Type_Bool
54
55 -- * Type 'Type_Fun_Bool'
56 -- | Convenient alias.
57 type Type_Fun_Bool lam
58 = Type_Root (Type_Alt Type_Var
59 (Type_Alt (Type_Fun lam)
60 Type_Bool))