#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707
#endif
module CLaSH.Core.Var
( Var (..)
, Id
, TyVar
, modifyVarName
)
where
import Unbound.LocallyNameless as Unbound
import Unbound.LocallyNameless.Name (isFree)
import CLaSH.Core.Term (Term)
import CLaSH.Core.Type (Kind, Type)
import CLaSH.Util
data Var a
= TyVar
{ varName :: Name a
, varKind :: Embed Kind
}
| Id
{ varName :: Name a
, varType :: Embed Type
}
deriving (Eq,Ord,Show)
type Id = Var Term
type TyVar = Var Type
Unbound.derive [''Var]
instance Alpha a => Alpha (Var a)
instance Subst Term Id
instance Subst Term TyVar
instance Subst Type TyVar
instance Subst Type Id where
subst tvN u (Id idN ty) | isFree tvN = Id idN (subst tvN u ty)
subst m _ _ = error $ $(curLoc) ++ "Cannot substitute for bound variable: " ++ show m
modifyVarName ::
(Name a -> Name a)
-> Var a
-> Var a
modifyVarName f (TyVar n k) = TyVar (f n) k
modifyVarName f (Id n t) = Id (f n) t