Brian Brian - 2 years ago 119
Scala Question

Interpreter auto-selection via Free Monad and Coproduct

I am playing with app architecture and free monads in haskell. I've got it down, except for how to lift my "instruction" into the correct slot of my coproduct without explicitly giving the full Left/Right path.

Here's the haskell example I've been working from:

Here, to inject types into the coproduct, we explicitly mention the path.

For instance:

Program :: Coproduct Interaction (Coproduct Auth Logging) a
logC :: (Functor f) => (forall a. Logging a -> f a) -> String -> Free f ()

logger :: String -> Free Program ()
logger = logC (Program . Coproduct . Right . Coproduct . Right)

Here, logger has to be put in the right slot in the coproduct manually with
Coproduct . Right . Coproduct . Right

Runar's talk in scala uses implicit type conversions and an Inject typeclass to achieve this result:

In short, I'm wondering if there's a way to do this in haskell.

Answer Source

Filling out the answer section from the comments to the original question...

The original Haskell paper can be found here: Data Types à la Carte

A Haskell implementation can be found here: ALaCarte.hs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download