| layout | developer-doc | ||||
|---|---|---|---|---|---|
| title | Monadic Contexts | ||||
| category | types | ||||
| tags |
|
||||
| order | 8 |
Coming from a Haskell background, we have found that Monads provide a great abstraction with which to reason about program behaviour, but they have some severe usability issues. The main one of these is the lack of automatic lifting, requiring users to explicitly lift computations through their monad transformer stack.
For a language as focused on usability as Enso is this really isn't feasible. To that end, we have created the notion of a 'Monadic Context', which is a monad transformer based on Supermonads (see references). These have special support in the compiler, and hence can be automatically lifted to aid usability.
The actionables for this section are:
- Think about subsumption for contexts.
- Contexts (e.g. IO) are represented using
T in IO. Multiple contexts are combined as standard(IO | State Int), and it is written the same in arg position.- Do we definitely want to use monads, or can we use arrows or other interpreter-based effects systems? These may aid with parallelism analysis.
There are three main notes about the syntax of contexts:
- Monadic contexts are defined using the
inkeyword (e.g.Int in IO). - We have a symbol
!, which is short-hand for putting something into theExceptionmonadic context. This is related to broken values. - Contexts can be combined by using the standard typeset operators, or nested
through repeated uses of
in.
It is also important to note that Enso has no equivalent to <- in Haskell.
Instead, pure computations are implicitly placed in the Pure monadic context,
and = acts to 'peel off' the outermost layer of contexts. As such, this means
that = always acts as bind, greatly simplifying how the type-checker has
to work.
Contexts can be defined by users.
The actionables for this section are:
- How, what, when and why?
The actionables for this section are:
- Specify and explain how automated lifting of monadic contexts works.
- It depends on the order of
runCtx
Enso includes a set of commonly-used monadic contexts as part of Base, its
standard library. These are listed below.
The actionables for this section are:
- Determine the full set of contexts that Enso should provide by default.
The actionables for this section are:
- Determine the granularity of IO (it's not one context, but a lot).
- Explain how there is no
runIO, and IO is just run at the program boundary, as well as the impacts of this.
The actionables for this section are:
- Determine exactly how state works (the fact that the 'keys' are preset by the
runState)- Describe how dependently-typed maps allow us to provide more flexible interfaces in future.