Giter Site home page Giter Site logo

minad / writer-cps-transformers Goto Github PK

View Code? Open in Web Editor NEW
10.0 6.0 3.0 69 KB

Compatibility package for old transformers: Stricter drop in replacements for WriterT and RWST

License: BSD 3-Clause "New" or "Revised" License

Haskell 100.00%
monad-transformers writer-monad haskell

writer-cps-transformers's Introduction

writer-cps-transformers's People

Contributors

int-index avatar louispan avatar minad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

writer-cps-transformers's Issues

Provide pattern synonyms to access internal representations.

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)

Add `exceptions` instances

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?

Do not provide liftCallCC'

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.