garyb / purescript-indexed-monad

MIT License
21 stars 11 forks source link

Separate IxEff/IxAff to own libraries #11

Open owickstrom opened 6 years ago

owickstrom commented 6 years ago

I'm using this library in a situation where Aff becomes problematic. Would it make sense to separate the Eff and Aff stuff to their own libraries?

garyb commented 6 years ago

Yeah, I think so - or it might not even be necessary at all really. I was thinking of providing a type that just lifts any Monad, since it's the operations that define the index transitions:

newtype IxM m i o a = IxM (m a)

derive instance newtypeIxM ∷ Newtype (IxM m i o a) _

runIxM ∷ forall m i o a. IxM m i o a → m a
runIxM (IxM ea) = ea

instance ixMonadIxM ∷ Monad m ⇒ IxMonad (IxM m) where
  ipure = IxM <<< pure
  ibind (IxM ma) f = IxM $ runIxM <<< f =<< ma

So that could then be newtyped yet again for specific things, like Middleware or wherever it is you're using next :smile:, and have a convenient ability to still derive newtype instance for the indexed stuff. I might add the various superclasses too then, IxFunctor, IxApply, etc. as it would be trivial to derive them for anything that can be defined in terms of IxM.

Sound good?

owickstrom commented 6 years ago

Even better! :smile:

For context, I'm using this library in https://github.com/owickstrom/purescript-leffe, and I want to use the bleeding edge PureScript compiler to have @ proxy syntax. For some reason Aff's dependency on datetime got me into trouble with instance deriving. I'm not using Aff in my project anyway, and removing the dependency solved it. I'll admit to being lazy and not investigating why datetime had trouble with the latest purs. :wink: