Skip to content

handlerHide2? #3

Description

@noughtmare

I'm trying to implement the effect-zoo scenarios to learn how to use this library. I'm stuck on the reinterpretation scenario. The scenario is that there is a Zooit effect that should be decomposed into a HTTP and a Logging effect. It is straightforward to write a naive solution:

{-# language FlexibleContexts #-}
module EffectZoo.Scenario.Reinterpretation.EvEff.Zooit where

import           Control.Ev.Eff
import           EffectZoo.Scenario.Reinterpretation.EvEff.HTTP
import           EffectZoo.Scenario.Reinterpretation.EvEff.Logging

newtype Zooit e ans = Zooit { listScenariosOp :: Op () [String] e ans }


listScenarios :: Zooit :? e => Eff e [String]
listScenarios = perform listScenariosOp ()


toLoggedHTTP :: (HTTP :? e, Logging :? e) => Eff (Zooit :* e) a -> Eff e a
toLoggedHTTP = handler Zooit
  { listScenariosOp = function
                        (\() -> do
                          logMsg "Fetching a list of scenarios"
                          lines <$> httpGET "/scenarios"
                        )
  }

But now the HTTP and Logging effects "leak" to the argument of toLoggedHTTP. If you only want to replace an effect by a single other effect, then you can use handlerHide, but I haven't been able to make that work with replacing one effect by two new effects. Is there a way to do this or do we need a handlerHide2 function?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions