garyb / purescript-indexed-monad

MIT License
21 stars 11 forks source link

How to implement IxMonadEff when using type indices for values #3

Open owickstrom opened 7 years ago

owickstrom commented 7 years ago

This is more me needing help, than issues with the library, I think. :)

Middleware is like a StateT monad, but with it's state transition indexed.

newtype Middleware m i o a = Middleware (i → m (Tuple a o))

I've tried to implement IxMonadEff for it, but got stuck at this:

instance ixMonadEffMiddleware ∷ MonadEff e m ⇒ IxMonadEff e (Middleware m) where
  iliftEff e = Middleware $ \s → do
    x ← liftEff (runIxEff e)
    pure (Tuple x s)
  Could not match type

    i1

  with type

    o2

The IxEff value describes a type transition i o in it's IxMonad instance, but that does not match Middleware in this case, as it does not change the indicies and it's state value. i o needs to be i i, I guess?

Any ideas?