{-# LANGUAGE CPP #-}
module Language.Embedded.Expression where
import Data.Typeable
#if __GLASGOW_HASKELL__ >= 800
import GHC.Types (Constraint)
#else
import GHC.Prim (Constraint)
#endif
import Language.C.Quote.C (ToIdent (..))
type VarId = String
class FreeExp exp
where
type FreePred exp :: * -> Constraint
constExp :: FreePred exp a => a -> exp a
varExp :: FreePred exp a => VarId -> exp a
data Val a
= ValComp VarId
| ValRun a
deriving Typeable
instance ToIdent (Val a) where toIdent :: Val a -> SrcLoc -> Id
toIdent (ValComp VarId
r) = VarId -> SrcLoc -> Id
forall a. ToIdent a => a -> SrcLoc -> Id
toIdent VarId
r
valToExp :: (FreeExp exp, FreePred exp a) => Val a -> exp a
valToExp :: Val a -> exp a
valToExp (ValComp VarId
v) = VarId -> exp a
forall (exp :: * -> *) a.
(FreeExp exp, FreePred exp a) =>
VarId -> exp a
varExp VarId
v
valToExp (ValRun a
a) = a -> exp a
forall (exp :: * -> *) a.
(FreeExp exp, FreePred exp a) =>
a -> exp a
constExp a
a
class FreeExp exp => EvalExp exp
where
evalExp :: exp a -> a