]> Git — Sourcephile - haskell/symantic.git/blob - Language/LOL/Symantic/Type/Int.hs
init
[haskell/symantic.git] / Language / LOL / Symantic / Type / Int.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.Int 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.Bool
17
18 -- * Type 'Type_Int'
19 -- | The 'Int' type.
20 data Type_Int (root:: * -> *) h where
21 Type_Int :: Type_Int root Int
22 type instance Root_of_Type (Type_Int root) = root
23 type instance Error_of_Type ast (Type_Int root) = Error_Type_Fun ast
24
25 instance -- Type_Eq
26 Type_Eq (Type_Int root) where
27 type_eq Type_Int Type_Int = Just Refl
28 instance -- Eq
29 Eq (Type_Int root h) where
30 x == y = isJust $ type_eq x y
31 instance -- Type_from AST
32 ( Type_Root_Lift Type_Int root
33 , Error_Type_Lift (Error_Type AST) (Error_of_Type AST root)
34 -- NOTE: require UndecidableInstances.
35 , Error_Type_Lift (Error_Type_Fun AST) (Error_of_Type AST root)
36 -- NOTE: require UndecidableInstances.
37 , Implicit_HBool (Is_Last_Type (Type_Int root) root)
38 ) => Type_from AST (Type_Int root) where
39 type_from _px_ty ast k =
40 case ast of
41 AST "Int" asts ->
42 case asts of
43 [] -> k $ type_root_lift Type_Int
44 _ -> Left $ error_type_lift $
45 Error_Type_Fun_Wrong_number_of_arguments 0 ast
46 _ -> Left $
47 case hbool :: HBool (Is_Last_Type (Type_Int root) root) of
48 HTrue -> error_type_lift $ Error_Type_Unsupported_from_root ast
49 HFalse -> error_type_lift $ Error_Type_Unsupported ast
50 instance -- String_from_Type
51 String_from_Type (Type_Int root) where
52 string_from_type Type_Int = "Int"
53 instance -- Show
54 Show (Type_Int root h) where
55 show = string_from_type
56
57 -- | Convenient alias to include a 'Type_Int' within a type.
58 type_int :: Type_Root_Lift Type_Int root => root Int
59 type_int = type_root_lift Type_Int
60
61 -- * Type 'Type_Fun_Int'
62 -- | Convenient alias.
63 type Type_Fun_Int lam = Type_Root (Type_Cons (Type_Fun lam) Type_Int)
64
65 -- * Type 'Type_Fun_Bool_Int'
66 -- | Convenient alias.
67 type Type_Fun_Bool_Int lam = Type_Root (Type_Cons (Type_Fun lam) (Type_Cons Type_Bool Type_Int))