]> 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 import Language.LOL.Symantic.Type.Var
18
19 -- * Type 'Type_Int'
20 -- | The 'Int' type.
21 data Type_Int (root:: * -> *) h where
22 Type_Int :: Type_Int root Int
23 type instance Root_of_Type (Type_Int root) = root
24 type instance Error_of_Type ast (Type_Int root) = ()
25
26 instance -- Type_Eq
27 Type_Eq (Type_Int root) where
28 type_eq Type_Int Type_Int = Just Refl
29 instance -- Eq
30 Eq (Type_Int root h) where
31 x == y = isJust $ x `type_eq` y
32 instance -- Type_from AST
33 ( Type_Root_Lift Type_Int root
34 , Error_Type_Lift (Error_Type AST) (Error_of_Type AST root)
35 , Implicit_HBool (Is_Last_Type (Type_Int root) root)
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_Wrong_number_of_arguments ast 0
44 _ -> Left $ error_type_unsupported px_ty 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
59 = Type_Root (Type_Alt Type_Var
60 (Type_Alt (Type_Fun lam)
61 Type_Int))
62
63 -- * Type 'Type_Fun_Bool_Int'
64 -- | Convenient alias.
65 type Type_Fun_Bool_Int lam
66 = Type_Root (Type_Alt Type_Var
67 (Type_Alt (Type_Fun lam)
68 (Type_Alt Type_Bool
69 Type_Int)))