Lambda-Calculus
LicenseApache License 2.0
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Transpiler.Scope

Description

Contains helpers for differentiating the behaviour conversions have on bound and unbound variables. Furthermore, this module enables for inlined variables.

Synopsis

Documentation

data ScopeTerm t #

Term that can refer to either the global scope or a bound variable.

Constructors

Inner t

Inner scope, referring to the term instantiated by a lambda at a certain depth.

Global

The global scope, which contains all variables that aren't inlined.

addDepth :: Integral a => a -> Expr (ScopeTerm a) -> Expr (ScopeTerm a) #

Adds depth to all bound variables so that an expression can be wrapped in a Lambda and still be valid.

toScopeTerm :: Expr a -> Expr (ScopeTerm a) #

Converts an expression containing only bound variables to a scoped expression.

toTerm :: Integral a => Expr (ScopeTerm a) -> Expr a #

Converts an expression containing scoped terms to one containing only scoped variables, with the assumption that the global scope is at depth 0.

accessIndex #

Arguments

:: Integral a 
=> Expr (ScopeTerm a)

The partition that access is being done on.

-> a

The length of this partition.

-> a

The term that needs to be accessed in this partition.

-> Expr (ScopeTerm a)

Expression which accesses this term.

Accesses the nth term of a partition of length l, by passing in truthAccessor and falseAccessor to access binary partitions of this partition.

makeGlobalAccessor :: Integral a => [String] -> String -> Maybe (Expr (ScopeTerm a)) #

Accesses a global variable from the global scope: see accessIndex for an in detail explanation of how this works.

accessMain :: Integral a => [String] -> Expr (ScopeTerm a) -> Maybe (Expr (ScopeTerm a)) #

Accesses main, but outside of the yCombinator: this enables a program to be run.

makeBoundAccessor :: Integral a => [String] -> String -> Maybe (Expr (ScopeTerm a)) #

Accesses a bound variable: as the bound term refers to a term at a higer level, the length of bound terms should not be added to this accessor.

makeAccessor #

Arguments

:: Integral a 
=> [String]

The list of bound variable names.

-> [String]

The list of global variable names.

-> (String -> Either String (Expr (ScopeTerm a)))

A function giving inlined expressions.

-> String

The variable wanting to be accessed.

-> Either String (Expr (ScopeTerm a))

The final expression that accesses the variable.

Accesses any variable: bound variables; global variables; inlined variables.

identifyInlineable #

Arguments

:: [(String, [String], a)]

A list containing tuples of, in order: variable name; dependencies; expressions.

-> [(String, a)]

A list containing tuples of, in order: inlineable variable names; expressions.

Identifies variables that can be inlined from a list of their dependencies.