garyb / purescript-indexed-monad

MIT License
21 stars 11 forks source link

Indexed Monad Transformer? #16

Open JordanMartinez opened 5 years ago

JordanMartinez commented 5 years ago

Should such a thing be in its own library? Or would it be worth it to include it here?

garyb commented 5 years ago

I spent some time playing with indexed transformers, based on Conor McBride's functional pearl about it, but I got stuck at a certain point and couldn't figure out how to make them useful... I think maybe we're missing features in PS that would make it work, plus the paper uses SHE features as well. I don't remember exactly what was wrong now, as it's been quite a while.

That was proper indexed transformers though, if you're just talking about something like IndexedT that allows a MonadTrans instance, then maybe there's something doable, assuming there's even anything that it's useful for!

JordanMartinez commented 5 years ago

Mm... Good to know.

I originally asked about this because hyper couldn't define an instance for MonadTrans for its IndexedMonad. I thought an indexed monad transformer might solve that in combination with using Indexed.

garyb commented 5 years ago

Oh, I see - you were talking about something like a MonadTransIx class?

JordanMartinez commented 5 years ago

Yeah, something like that.

I'd imagine it would be defined like this?

class MonadTransIx t where
   liftIx :: forall m x y a. IxMonad m x y a -> t m i o a

liftIndexed :: forall t m i o a. MonadTransIx t => Monad m => m a -> t m i o a
liftIndexed = liftIx <<< Indexed
garyb commented 5 years ago

I'm not sure that'd be helpful in the case of hyper, since it's lifting an unindexed monad. Your definition looks a little off too :wink:, here's what I think you meant, and the other option which is what lift' does in hyper:

class IxMonadTrans t where
   liftIx :: forall m x y a. IxMonad m => m x y a -> t m x y a

class IxMonadTrans' t where
   liftIx' :: forall m x a. Monad m => m a -> t m x x a
JordanMartinez commented 5 years ago

Ah, whoops!

Yeah, I guess it's not helpful in this case. Still, thanks for your response.

Should I close this issue as it's not really about what you initially thought it was? Similar to purescript-transformers, if there was a desire to add indexed transformers, would that exist in a library called purescript-transformers-indexed?