3 ms·
One of the design aspects is to make a distinction between functions with and without side effects (pure). In a way to tell these apart by looking at the functi
by cleue 3y ago
One of the design aspects is to make a distinction between functions with and without side effects (pure). In a way to tell these apart by looking at the function signature without having to read the function body.
The library uses a function signature without an input but with an output for this purpose. Aside from the trivial case of a constant function, such a signature can only mean that the function has side effects.
type IO[A any] func() A
If you consider this a valid approach, then the set of monadic helper functions make it easier to compose these effectful functions with pure functions.
This article https://betterprogramming.pub/investigating-the-i-o-monad-in-go-3c0fabbb4b3d https://betterprogramming.pub/investigating-the-i-o-monad-in... contains some more detailed reasoning.