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