|
|
|
|
|
by Tarean
3362 days ago
|
|
We can look at effects as a dsl built upon a monad. The state effect lets us get and put state, for instance. There are two extensible ways to represent this: data State a self = Get self | Put a self
class State repr where
get :: repr a
put :: a -> repr ()
With the first implementation we write a function that interprets the adt, writing different interpreters is easy. We parametrized over self so we can combine languages by combining their adt's and give that as self. To tie the knot we use use recursion and end up with the free monad.With the second version we depend on multiple type classes to combine languages and implement them for different types to get different interpreters. The big advantage with this approach is that we don't have to construct the adt's before interpreting which is where the speed difference comes from. Tl;dr: if you want to go fast you have to skip constructing adts and if you do that you end up with something like haskell's mtl. |
|