Given an applicative f
, what constructions are there that I can apply to f
that make it a monad? Ideally, the monad would not be completely free, but satisfy a <*> b == ap a b
. Does such a construction exist? If everything fails, I can always use Free f
, but that will usually be “too free”. The reason I want that equation to hold is because my Applicative
instance is very performant, and I don’t want to lose that by later slowly interpreting the free structure.
In my use case, I have a type operator t
that has a very efficient singleton :: a -> t a
and cartesian :: t a -> t b -> t (a, b)
, but no Functor
. So I implemented:
data Coyoneda b = forall a . Coyoneda
{ t :: t a
, f :: a -> b
}
Now I want to create a free monad on top of that. Maybe there is a shortcut that passes directly from t
to a free monad that will reuse singleton
and cartesian
? The trouble with Free
, operational
etc. is that they will typically implement <*> = ap
, which uses the free structure, but doesn’t reuse cartesian
.