]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Type/Var.hs
init
[haskell/symantic.git] / Language / Symantic / Type / Var.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE GADTs #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE TypeFamilies #-}
5 -- | Type variable.
6 module Language.Symantic.Type.Var
7 ( module Language.Symantic.Type.Var
8 , module Language.Symantic.Lib.Data.Peano
9 ) where
10
11 import Data.Maybe (isJust)
12
13 import Language.Symantic.Type.Common
14 import Language.Symantic.Lib.Data.Peano
15
16 -- * Type 'Type_Var'
17 -- | The variable type.
18 data Type_Var (root:: * -> *) p where
19 Type_Var :: SPeano p -> Type_Var root p
20 type instance Root_of_Type (Type_Var root) = root
21 type instance Error_of_Type ast (Type_Var root) = No_Error_Type
22
23 instance -- Type_Eq
24 Type_Eq (Type_Var root) where
25 type_eq (Type_Var x) (Type_Var y) = x `peano_eq` y
26 instance -- Eq
27 Eq (Type_Var root h) where
28 x == y = isJust $ x `type_eq` y
29 instance -- String_from_Type
30 String_from_Type (Type_Var root) where
31 string_from_type (Type_Var p) =
32 "t" ++ show (integral_from_peano p::Integer)
33 instance -- Show
34 Show (Type_Var root h) where
35 show = string_from_type
36 instance Type_Constraint Eq (Type_Var root)
37 instance Type_Constraint Ord (Type_Var root)
38
39 -- | Convenient alias to include a 'Type_Var' within a type.
40 type_var :: Type_Root_Lift Type_Var root => SPeano p -> root p
41 type_var = type_root_lift . Type_Var