lexi-lambda / freer-simple

A friendly effect system for Haskell
https://hackage.haskell.org/package/freer-simple
BSD 3-Clause "New" or "Revised" License
228 stars 20 forks source link

Add a function to map the effect list #37

Open sjoerdvisscher opened 2 years ago

sjoerdvisscher commented 2 years ago

After a bit of refactoring some freer-simple related code I ended up with this function:

mapEffs :: (Union effs ~> Union effs') -> Eff effs ~> Eff effs'
mapEffs f = loop where
    loop = \case
        Val a -> pure a
        E u q -> E (f u) (tsingleton $ qComp q loop)

It seems this might a useful thing to add to the library. Note that I have no idea if this implementation is a good one (or even if it makes sense really.)