Skip to content
This repository was archived by the owner on Jan 17, 2020. It is now read-only.

Commit b37308c

Browse files
authored
Update README.md
1 parent f44797c commit b37308c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@ catchable exception.
2525
Under the covers, `IO` is based on `Aff`, and there is no wrapper so there is
2626
no runtime overhead or performance penalty for `IO`.
2727

28+
# Effects vs MTL
29+
30+
In MTL, we would denote effects using type classes:
31+
32+
```haskell
33+
class (Monad m) <= MonadConfig m where
34+
readConfig :: m Config
35+
36+
serverAddress :: forall m. (MonadConfig m) => m InetAddress
37+
```
38+
39+
This serves a similar purpose to effect rows in PureScript, whereby every "label" corresponds to a set of functionality described by a type class. The advantage to using classes over labels is that the semantics can be well-described by the classes.
40+
41+
Similarly, if we were using `Free` directly, instead of using type classes to abstract over a `Free` encoding, we would denote effects using functors:
42+
43+
```
44+
class ConfigF a
45+
= ReadConfig (Config -> a)
46+
47+
serverAddress :: PrismT' f ConfigF -> Free f InetAddress
48+
```
49+
50+
In this case, we have all the benefits of finely-grained effects, including semantic descriptions of those effects, but without needing to use labels in effect rows.
51+
52+
In either MTL or direct-Free encodings, we have all the tools necessary to provide clear information to developers to help them reason about the code they are writing — all without using effect rows.
53+
54+
Therefore, MTL and direct-Free approaches can be considered alternatives to PureScript's own effect system (which is implemented as a library, and not baked into PureScript). When using one of these alternatives, it can simplify code and improve type inference to use `IO` instead of trying to doubly-encode effects using two systems — one of which has no semantic or algebraic basis.
55+
2856
# Usage
2957
3058
`IO` only has one function, which should only be used in your `main`:

0 commit comments

Comments
 (0)