module CLaSH.Core.Term
( Term (..)
, TmName
, LetBinding
, Pat (..)
)
where
import Control.DeepSeq
import Data.Text (Text)
import GHC.Generics
import Unbound.Generics.LocallyNameless
import Unbound.Generics.LocallyNameless.Extra ()
import CLaSH.Core.DataCon (DataCon)
import CLaSH.Core.Literal (Literal)
import CLaSH.Core.Type (Type)
import CLaSH.Core.Var (Id, TyVar)
data Term
= Var Type TmName
| Data DataCon
| Literal Literal
| Prim Text Type
| Lam (Bind Id Term)
| TyLam (Bind TyVar Term)
| App Term Term
| TyApp Term Type
| Letrec (Bind (Rec [LetBinding]) Term)
| Case Term Type [Bind Pat Term]
deriving (Show,Generic,NFData)
type TmName = Name Term
type LetBinding = (Id, Embed Term)
data Pat
= DataPat (Embed DataCon) (Rebind [TyVar] [Id])
| LitPat (Embed Literal)
| DefaultPat
deriving (Show,Generic,NFData,Alpha)
instance Eq Term where
(==) = aeq
instance Ord Term where
compare = acompare
instance Alpha Term where
fvAny' c nfn (Var t n) = fmap (Var t) $ fvAny' c nfn n
fvAny' c nfn t = fmap to . gfvAny c nfn $ from t
aeq' c (Var _ n) (Var _ m) = aeq' c n m
aeq' _ (Prim t1 _) (Prim t2 _) = t1 == t2
aeq' c t1 t2 = gaeq c (from t1) (from t2)
acompare' c (Var _ n) (Var _ m) = acompare' c n m
acompare' _ (Prim t1 _) (Prim t2 _) = compare t1 t2
acompare' c t1 t2 = gacompare c (from t1) (from t2)
instance Subst Type Pat
instance Subst Term Pat
instance Subst Term Term where
isvar (Var _ x) = Just (SubstName x)
isvar _ = Nothing
instance Subst Type Term