Overview
Probably you have heard of side effects - usually it refers to some state modifactions you are not able to control.
However, effects is a more general term. Effect
is a way to focus on values rather on things that also happen during program execution.
Forgetting details
From now on, you can think on effects as parameterized types with an ability on focusing on their parameters.
As an example, imagine we have such an expression:
We can treat Optional as an effect since we can forget that it exists and focus on an Integer
value instead.
In case of Optional, we can covariantly map a function so we don’t care if Integer
value even exists:
Labeled binding
You can consider natural transformations that invole Kleisli categories as binding morphisms. In Я all binding operators (like yok/yokl) should have a label - they tell both an engineer and a language what kind of binding we want to use.
We can bind a function so this expression, so if we don’t have an integer in expression
, whichever function we apply - we get None
in the end:
Also we can traverse over Optional
value, so the function would pick up the value only if there is Some
:
Types of parameters
Imagine we have a function that can say if the provided integer is odd:
In this case you can modify Integer
parameter contravariantly and Boolean
parameter covariantly:
Jointed effects
Effects could be jointed so if you affect any effect in a joint, it could affect all others as well.
Let’s say you have a stateful computation that you would like to abort at some point. For abortion you have Error effect. So you just need to joint them together.