minad / writer-cps-transformers Goto Github PK
View Code? Open in Web Editor NEWCompatibility package for old transformers: Stricter drop in replacements for WriterT and RWST
License: BSD 3-Clause "New" or "Revised" License
Compatibility package for old transformers: Stricter drop in replacements for WriterT and RWST
License: BSD 3-Clause "New" or "Revised" License
The current transformers
(0.5.6.2) does not expose the internal representations of Control.Monad.Trans.Writer.CPS
or Control.Monad.Trans.RWS.CPS
. This makes it impossible to implement certain things, ex. MFunctor
from the mmorph
package. The transformers
package has had an ongoing issue for about a year, but even in the case of an update, some packages may want to maintain backward-compatibility.
In version 0.5.5.0, this package exported the modules Control.Monad.Trans.Writer.CPS.Internal
and Control.Monad.Trans.RWS.CPS.Internal
, which exposed these representations.
My proposal is to re-add these modules, exporting the original interface with the addition of the following pattern synonyms:
{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
pattern WriterT :: (w -> m (a, w)) -> WriterT w m a
pattern WriterT x = (unsafeCoerce -> x)
where WriterT x = unsafeCoerce x
{-# COMPLETE WriterT #-}
pattern RWST :: (r -> s -> w -> m (a, s, w)) -> WriterT w m a
pattern RWST x = (unsafeCoerce -> x)
where RWST x = unsafeCoerce x
{-# COMPLETE RWST #-}
Because these datatypes are implemented via newtype
, this usage of unsafeCoerce
is safe with ghc
.
This allows for implementation of MFunctor
:
instance MFunctor (WriterT w) where
hoist :: Monad m => (forall a. m a -> n a) -> WriterT w m b -> WriterT w n b
hoist nat (WriterT m) = WriterT $ \w -> nat (m w)
I found myself needing the MonadThrow and MonadCatch instances of the CPS version of WriterT , so I understand they should appear here, though this will introduce a new exceptions
dependency.
What do you think?
https://github.com/louispan/writer-cps-lens can be used once the Internal module code is merged.
The fact that this implementation of Writer
is under the hood a State
shouldn't show up in the public interface.
In particular, there shouldn't be a liftCallCC'
function in the public module. Only liftCallCC
should be provided and it should behave like the one for Writer
, not like the one for State
.
I had to find #7 to understand why there are no module listed at http://hackage.haskell.org/package/writer-cps-transformers-0.5.6.0.
Would you mind properly deprecating the package and directing people to transformers
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.