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