]> 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 {-# OPTIONS_GHC -fno-warn-missing-methods #-}
6 -- | Type variable.
7 module Language.Symantic.Type.Var
8 ( module Language.Symantic.Type.Var
9 , module Language.Symantic.Lib.Data.Peano
10 ) where
11
12 import Data.Maybe (isJust)
13
14 import Language.Symantic.Type.Common
15 import Language.Symantic.Lib.Data.Peano
16
17 -- * Type 'Type_Var'
18 -- | The variable type.
19 data Type_Var (root:: * -> *) p where
20 Type_Var :: SPeano p -> Type_Var root p
21 type instance Root_of_Type (Type_Var root) = root
22 type instance Error_of_Type ast (Type_Var root) = No_Error_Type
23
24 instance -- Eq_Type
25 Eq_Type (Type_Var root) where
26 eq_type (Type_Var x) (Type_Var y) = x `peano_eq` y
27 instance -- Eq
28 Eq (Type_Var root h) where
29 x == y = isJust $ x `eq_type` y
30 instance -- String_from_Type
31 String_from_Type (Type_Var root) where
32 string_from_type (Type_Var p) =
33 "t" ++ show (integral_from_peano p::Integer)
34 instance -- Show
35 Show (Type_Var root h) where
36 show = string_from_type
37 instance Constraint_Type Eq (Type_Var root)
38 instance Constraint_Type Ord (Type_Var root)
39 instance Unlift_Type1 Type_Var
40 instance Eq_Type1 (Type_Var root)
41
42 -- | Convenient alias to include a 'Type_Var' within a type.
43 type_var :: Lift_Type_Root Type_Var root => SPeano p -> root p
44 type_var = lift_type_root . Type_Var