|Instruction||What it does|
||Applies the lambda function after it to whatever is after that lambda function.|
||Defines a lambda function.|
||Gets the current function's argument.|
||Returns the current function.|
||When applied to something, prints it and returns it unchanged.|
||Returns its argument plus one.|
||Returns its argument minus one.|
||If its argument is equivalent to (0), returns the identity function.|
||Returns the literal value of n, rather than its 0587 value.|
An 0587 program consists of one function application. Due to higher-order functions, this isn't as bad as it sounds; You can create functions inside of functions! For example, this program does a "Hello World" in a fancy monadic way:
0 104029 1(Hello World)
(Code is indented for readability)
As you can see, the program takes a function that calls
4 on its argument to a function that returns "Hello World".
Monads and Closures
Monads are a very important concept in 0587. But instead of being a value wrapped in an algebraic datatype (like in Haskell), they are a value wrapped in a function.
It's pretty simple to create a monad. Just write this:
In this example, "Hello World" is being held inside an anonymous function.
Getting the value out of a monad is substantially more tricky. There is a function combination for retrieving a value from a monad:
This lambda function, when applied to a monad, will apply
9 (or null) to it and return the result. Since monads don't care about their arguments, you can safely call it with
9 and get the result. In fact, that's why
9 was included with the language in the first place.
Monads are important because of closures. Closures are lambdas that contain something from another scope. All closures (in 0587 at least) are monads because they are just a value wrapped in a function.
Or a fancier way: