an API for constructing HOAS expressions

This commit is contained in:
krangelov
2021-12-09 07:46:49 +01:00
parent e312a10882
commit d1b1cd6e8c
2 changed files with 15 additions and 2 deletions

View File

@@ -28,8 +28,9 @@ module PGF2 (-- * PGF
-- ** Expressions -- ** Expressions
Expr(..), Literal(..), showExpr, readExpr, Expr(..), Literal(..), showExpr, readExpr,
mkAbs, unAbs, mkAbs, unAbs, Var,
mkApp, unApp, unapply, mkApp, unApp, unapply,
mkVar, unVar,
mkStr, unStr, mkStr, unStr,
mkInt, unInt, mkInt, unInt,
mkDouble, unDouble, mkDouble, unDouble,

View File

@@ -1,10 +1,11 @@
module PGF2.Expr(Var, Cat, Fun, module PGF2.Expr(Var, Cat, Fun, Var,
BindType(..), Literal(..), Expr(..), BindType(..), Literal(..), Expr(..),
Type(..), Hypo, Type(..), Hypo,
Patt(..), Equation(..), Patt(..), Equation(..),
mkAbs, unAbs, mkAbs, unAbs,
mkApp, unApp, unapply, mkApp, unApp, unapply,
mkVar, unVar,
mkStr, unStr, mkStr, unStr,
mkInt, unInt, mkInt, unInt,
mkDouble, unDouble, mkDouble, unDouble,
@@ -107,6 +108,17 @@ unapply = extract []
extract es (EImplArg e) = extract es e extract es (EImplArg e) = extract es e
extract es h = (h,es) extract es h = (h,es)
-- | Constructs a variable expression from a de Bruijn index
mkVar :: Int -> Expr
mkVar = EVar
-- | Extracts the de Bruijn index of a variable
unVar :: Expr -> Maybe Int
unVar (EVar i) = Just i
unVar (ETyped e ty) = unVar e
unVar (EImplArg e) = unVar e
unVar _ = Nothing
-- | Constructs an expression from string literal -- | Constructs an expression from string literal
mkStr :: String -> Expr mkStr :: String -> Expr
mkStr s = ELit (LStr s) mkStr s = ELit (LStr s)