meisl / lambda Goto Github PK
View Code? Open in Web Editor NEWA calculator for Lambda calculus
A calculator for Lambda calculus
curryOptions
replacing the current $STATS_ENABLED
Steps:
t
for var x
" arg accept a list of those Pair
s (#29), to be applied one after the other, in the order they appear in the list (-> transitively). Use None
(Maybe
, #28) as a return value indicating no change and Some t'
if the result is indeed a different term t'
; in order to support maximal sharing.Maybe Term
as return type for sharing.Consider using bit-strings (List Bool
) for the type/ctor-tag. This would require to re-do ADT List with at least three-way mutual recursion (-> #33), but has the benefit of greatly simplifying the task of adding more ctors to an ADT.
It'd also open up an easy way of adding support for (runtime) type tags as well: instead a flat List Bool
we'd use a List (List Bool)
, one determining the runtime type, another determining the ctor used, ....
We might even provide the actual fields of the ADT instance in a List (rather than as top-level args), thus making the interface for both, predicates and projections completely uniform.
First main improvement should be to replace several nested if
s by a construct which adds only one level of nesting, independent of the nr of constructors ("ctors").
Secondly, it should improve efficiency in itself already, by reducing the nr of tests to constant 1 as opposed to linear in the nr of ctors of the ADT ("in itself already" meaning: prior to any further compiler optimizations).
The exact inner workings of this depend of course on which pattern is chosen for implementing ADT(-ctor)s in λ: do we have type/ctor tags or not? If so, how to encode them? If not (-> some form of callback convention), then who calls back whom, and maybe there's some indirection?.
Anyhow,
data Bool = False | True
: in such cases lazy evaluation is imperative - so to simulate that in Perl we'll pass a 0-arity Block to indicate that lazy evaluation is needed.Rather than repeating by hand the same pattern over and over in each and every concrete ADT, we'd like to abstract from the actual λ-implementation of ADTs^1: given some representation of an ADT (abstract description of its ctors and for each of them, the fields and their types, see #7), provide all the standard fns (ctors, predicates, projections, case-construct, full-blown pattern-matching).
Making this separation will allow for two things:
This - hence all pts below - really are to approached from two sides:
So, given an ADT (representation), auto-generate:
[1] what, actually, are the fns doing which represent instances of the ADT at hand? Do we use tags to differentiate types / ctors? Or do we implement the ctors themselves as "selectors"? In case of tags, how do we encode the tags? etc...
mostly à la Scheme:
;
;(
... )
Maybe
(Church-encoded by hand, everything in λ, too)'Pair
(Church-encoded by hand, everything in λ, too)'List
(Church-encoding by hand, everything in λ, too)'Term
for syntax tree / AST entities (Church-encoded by hand)'Term
alone to represent Terms' (branch "switch_to_lambda_repres")Either
't
for var x
" arg accept a list of those Pair
s (#29), to be applied one after the other, in the order they appear in the list (-> transitively). Use None
(Maybe
, #28) as a return value indicating no change and Some t'
if the result is indeed a different term t'
; in order to support maximal sharing.Maybe Term
as return type for sharing.Term
(simple but correct)'Term
: clever & efficient & flexible!'multi postcircumfix:<( )> (...)
with appropriate signatures (nest actual sig in extra parens (
and )
, since we'll be passed a capture); avoid introducing extra "internal" methods like "apply" etc.List Bool
) for the type/ctor-tag. This would require to re-do ADT List with at least three-way mutual recursion (-> #33), but has the benefit of greatly simplifying the task of adding more ctors to an ADT.List Bool
we'd use a List (List Bool)
, one determining the runtime type, another determining the ctor used, ....data Bool = False | True
: in such cases lazy evaluation is imperative - so to simulate that in Perl we'll pass a 0-arity Block to indicate that lazy evaluation is needed....
...rather than stupid substitution/rewriting
see #31
A simple, not-too-clever expansion (either of source text, in the syntax tree or the AST).
This is meant just to make slightly more complicated constructions actually feasible, ie not have you get lost in unmatched parentheses / trying to figure out what gets bound to which.
Requirements:
[Note: the following requirements have been dropped:
This will require ADT Term (#10) to support more fields (more than just the two for AppT and LamT)
...well, depends on how ADT's are actually implemented (now we're at a Church encoding)
If used for syntax nodes as well (as opposed to only for _abstract_ stx nodes), then we'll most probably need more than 4 constructors, thus requiring more than 2 "tag" bits in the Church encoding.
Make applying a Perl6 function feel like applying it in λ:
Routine
s, not Block
s)multi invoke (...)
with appropriate signatures (nest actual sig in extra parens (
and )
, since we'll be passed a capture); avoid introducing extra "internal" methods like "apply" etc.Note: this of course excludes the following Perl6 features:
requires #2, and probably a List ADT
oh...
done in 0883bbd
data Either a b = Left a
| Right b
yes, by inserting thunks for consequence and alternative
REPL = "Read" - "Eval" - "Print" - "Loop"
"
(double-quotes) to indicate start and end\
(back-slash) for escape inside two "
s:
\"
for a "
character\\
for a \
character\n
for a newline character (0xA)\r
for a carriage-return (0xD)\t
for a tab character (0x9)\b
and \f
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.