Safe Haskell | None |
---|---|
Language | Haskell2010 |
Example implementation of untyped \(\lambda\)-calculus with the foil.
Synopsis
- data Expr (n :: S) where
- substitute :: forall (o :: S) (i :: S). Distinct o => Scope o -> Substitution Expr i o -> Expr i -> Expr o
- whnf :: forall (n :: S). Distinct n => Scope n -> Expr n -> Expr n
- whnf' :: Expr 'VoidS -> Expr 'VoidS
- nf :: forall (n :: S). Distinct n => Scope n -> Expr n -> Expr n
- nf' :: Expr 'VoidS -> Expr 'VoidS
- ppName :: forall (n :: S). Name n -> String
- ppExpr :: forall (n :: S). Expr n -> String
- lam :: forall (n :: S). Distinct n => Scope n -> (forall (l :: S). DExt n l => Scope l -> NameBinder n l -> Expr l) -> Expr n
- churchN :: Int -> Expr 'VoidS
Documentation
>>>
import Control.Monad.Foil
data Expr (n :: S) where Source #
Untyped \(\lambda\)-terms in scope n
.
VarE :: forall (n :: S). Name n -> Expr n | Variables are names in scope |
AppE :: forall (n :: S). Expr n -> Expr n -> Expr n | Application of one term to another: \((t_1, t_2)\) |
LamE :: forall (n :: S) (l :: S). NameBinder n l -> Expr l -> Expr n | \(\lambda\)-abstraction introduces a binder and a term in an extended scope: \(\lambda x. t\) |
Instances
InjectName Expr Source # | |
Defined in Control.Monad.Foil.Example | |
Sinkable Expr Source # | This instance serves as a proof
that sinking of |
Defined in Control.Monad.Foil.Example | |
RelMonad Name Expr Source # | |
Show (Expr n) Source # | Use |
NFData (Expr l) Source # | |
Defined in Control.Monad.Foil.Example |
substitute :: forall (o :: S) (i :: S). Distinct o => Scope o -> Substitution Expr i o -> Expr i -> Expr o Source #
Substitution for untyped \(\lambda\)-terms. The foil helps implement this function without forgetting scope extensions and renaming.
whnf :: forall (n :: S). Distinct n => Scope n -> Expr n -> Expr n Source #
Compute weak head normal form (WHNF) of a \(\lambda\)-term.
>>>
whnf emptyScope (AppE (churchN 2) (churchN 2))
λx1. (λx0. λx1. (x0 (x0 x1)) (λx0. λx1. (x0 (x0 x1)) x1))
whnf' :: Expr 'VoidS -> Expr 'VoidS Source #
Compute weak head normal form (WHNF) of a closed \(\lambda\)-term.
>>>
whnf' (AppE (churchN 2) (churchN 2))
λx1. (λx0. λx1. (x0 (x0 x1)) (λx0. λx1. (x0 (x0 x1)) x1))
nf :: forall (n :: S). Distinct n => Scope n -> Expr n -> Expr n Source #
Compute normal form (NF) of a \(\lambda\)-term.
>>>
nf emptyScope (AppE (churchN 2) (churchN 2))
λx1. λx2. (x1 (x1 (x1 (x1 x2))))
nf' :: Expr 'VoidS -> Expr 'VoidS Source #
Compute normal form (NF) of a closed \(\lambda\)-term.
>>>
nf' (AppE (churchN 2) (churchN 2))
λx1. λx2. (x1 (x1 (x1 (x1 x2))))
ppExpr :: forall (n :: S). Expr n -> String Source #
Pretty-print a \(\lambda\)-term.
>>>
ppExpr (churchN 3)
"\955x0. \955x1. (x0 (x0 (x0 x1)))"