You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library mmtl has a MonadFix (Codensity m) instance
-- still need to prove that MonadFix laws holdinstanceMonadFixm=>MonadFix (Codensitym) wheremfix:: (a->Codensityma) ->Codensityma
mfix f = lift (mfix (lowerCodensity . f))
I'm using Codensity to ensure timely resource cleanup (like a transformer version of the managed library), in which case this is not going to be the instance you want, since it will run your finalizers early, as you exit the mdo block.
Another option is to use a lazily-evaluated promise for the result, mirroring the approach in fixIO:
fixCodensity::MonadIOm=> (a->Codensityma) ->Codensityma
fixCodensity f =Codensity\k ->do
promise <- liftIO $IORef.newIORef (error"result eval'd too early")
ans <- liftIO $ unsafeDupableInterleaveIO (IORef.readIORef promise)
runCodensity (f ans) \a ->do
liftIO $IORef.writeIORef promise a
k a
This is also probably not the instance you'd want in a general-purpose library, but I figured I'd put it here for reference.
instanceMonadFixm=>MonadFix (Codensitym) where
mfix f =Codensity (\ka -> mfixing (\a -> runCodensity (f a) ka<&>(,a)))
where mfixing f =fst<$> mfix (\~(_,a) -> f a )
The library mmtl has a
MonadFix (Codensity m)
instancehttps://hackage.haskell.org/package/mmtl-0.1/docs/Control-Monad-Codensity.html
The text was updated successfully, but these errors were encountered: