Functor is an object with a map function which obeys a few rules
*is the kind of every type. We can also help our brains by using the word
Type -> Typeis a type constructor which takes one type as a parameter and returns another any type.
Type -> Type -> Typeis also a type constructor but it takes two types and gives you another.
Type -> Type -> Type -> Typeand so on …
Type constructors are refered to as a kind of
* -> * or higher. Because of this, they are called higher-kinded types. So often this term is used as a way of referring to languages that have first-class support for higher-kinded types.
You also have the ability to specify a type like so:
type E a = Either Error a
Think of a Kind as type of types.
“In type theory, a kind is the type of a type constructor”
type kind = Big<number>;
A Monad is a generic type which is wrapped up. It can be created from any non-null type. It can be composed. There is some way of applying a function which takes the underlying type to a Monad of that type.
- Constructors being given an existing Monad should wrap the original value rather than the Monad
- Applying a function to the Monad should do the work on the value directly and return a Monad of the result
Monads should be able to be composed
- Eric Lippert talks about Monads
- The Marvels of Monads by Wes Dyer
- Monadster by Scott Wlaschin
- Fantas, Eel, and Specification 15: Monad
A Monoid is a Semigroup which also has a value which when concatenated to any value doesn’t change it. For example with a addition concatenating a
0 will not change the number you started with or with multiplication concatenating a
1 will not change the original number.
This idea brings together a few patterns including streams and data flows. They allow the system to react to changes within the data instantly, update the user interface to reflect them and do so in a performant and less complex way.
The code can therefor:
Base programming logic on what is known at the given moment. Have a clear sense of who can change what data Be told when data has changed and it is safe and performant to update
A semi group is something which can be concatenated together. It is associative which means that it doesn’t matter how you group the concatenation, it will always end up with the same result - like addition where 1 + 1 + 1 is the same as (1 + 1) + 1.