Fantasy World
General
Collection of the Fantasy-Land implementations.
Fantasy-Land:
- daggy
- Fantasy-Combinators
- Fantasy-Identities
- Fantasy-Promises
- Fantasy-Validations
- Fantasy-States
- Fantasy-Options
- Fantasy-Eithers
- Fantasy-IO
- Fantasy-Tuples
- Fantasy-Cofrees
- Fantasy-Readers
- Fantasy-Stores
- Fantasy-Lenses
Prelude
Fantasy World also includes a collection of functions that make it easier to develop in Fantasy Land.
(More information to come)
Environment
An environment holds methods and properties.
Methods are implemented as multi-methods, which allow a form of ad-hoc polymorphism. Duck typing is another example of ad-hoc polymorphism, but only allows a single implementation at a time, via prototype mutation.
A method instance is a product of a name, a predicate and an implementation:
var env = fantasy method // Name 'negate' // Predicate { return typeof n == 'number'; } // Implementation { return -n; } ; env == -100;
We can now override the environment with Some more implementations:
var env2 = env method 'negate' { return typeof b == 'boolean'; } { return !b; } ; env2 == -100; env2 == false;
Environments are immutable; references to env
won't see an
implementation for boolean. The env2
environment could have
overwritten the implementation for number and code relying on env
would still work.
Properties can be accessed without dispatching on arguments. They can almost be thought of as methods with predicates that always return true:
var env = fantasy ; envname === 'Fantasy';