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:

expression: Optional Integer

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:

Some 0 `yo` is `hu` 1 `AR___` Some 1
None _ `yo` is `hu` 1 `AR___` None _

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:

Some 0 `yok` Try `ha` Some `AR___` Some 0
None _ `yok` Try `ha` Some `AR___` None _

Also we can traverse over Optional value, so the function would pick up the value only if there is Some:

Some 0 `yokl` Console.output `AR___` 0
None _ `yokl` Console.output `AR___`

Types of parameters

Imagine we have a function that can say if the provided integer is odd:

odd: Integer `AR_` Boolean

In this case you can modify Integer parameter contravariantly and Boolean parameter covariantly:

odd `yai` is `hu` 0 `la` is `hu` 1
odd `yio` not

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.

State _ `JNT` Error _