writer-cps-lens (empty) → 0.1.0.0
raw patch · 6 files changed
+139/−0 lines, 6 filesdep +basedep +lensdep +profunctorssetup-changed
Dependencies added: base, lens, profunctors, transformers, writer-cps-mtl, writer-cps-transformers
Files
- LICENSE +30/−0
- README.md +8/−0
- Setup.hs +2/−0
- src/Control/Monad/Trans/RWS/CPS/Lens.hs +37/−0
- src/Control/Monad/Trans/Writer/CPS/Lens.hs +30/−0
- writer-cps-lens.cabal +32/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,8 @@+# Control.Lens instances for CPS WriterT and RWST monad transformers++[](https://hackage.haskell.org/package/writer-cps-lens)+[](http://travis-ci.org/louispan/writer-cps-lens)+* Wrapped, Rewrapped, Magnify and Zoomed instances+* https://hackage.haskell.org/package/writer-cps-transformers+* https://hackage.haskell.org/package/writer-cps-mtl+* https://hackage.haskell.org/package/writer-cps-monads-tf
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Control/Monad/Trans/RWS/CPS/Lens.hs view
@@ -0,0 +1,37 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}++module Control.Monad.Trans.RWS.CPS.Lens where++import Control.Lens+import Control.Lens.Internal.Zoom+import Control.Monad.RWS.CPS as Strict+import Control.Monad.Trans.RWS.CPS.Internal as Strict+import Data.Profunctor.Unsafe++-- | Unlike normal Wrapped instances, this doesn't simply peel off the newtype wrapper,+-- as that will expose the hidden CPS w state.+-- Based on code from Control.Lens.Wrapped+instance (Monoid w, Functor m, t ~ Strict.RWST r' w' s' m' a') => Rewrapped (Strict.RWST r w s m a) t+instance (Monoid w, Functor m) => Wrapped (Strict.RWST r w s m a) where+ type Unwrapped (Strict.RWST r w s m a) = r -> s -> m (a, s, w)+ _Wrapped' = iso Strict.runRWST Strict.rwsT+ {-# INLINE _Wrapped' #-}++-- | The Zoomed instance uses the RWST.Internal constructor to avoid a @Monoid w@ constraint.+-- | Based on code from Control.Lens.Zoomed+type instance Zoomed (Strict.RWST r w s z) = FocusingWith w z+instance Monad z => Zoom (Strict.RWST r w s z) (Strict.RWST r w t z) s t where+ zoom l (Strict.RWST m) = Strict.RWST $ \r s w ->+ (unfocusingWith #. l (FocusingWith #. (\s' -> m r s' w))) s+ {-# INLINE zoom #-}++-- | The Magnified instance uses the RWST.Internal constructor to avoid a @Monoid w@ constraint.+type instance Magnified (Strict.RWST a w s m) = EffectRWS w s m+instance Monad m => Magnify (Strict.RWST b w s m) (Strict.RWST a w s m) b a where+ magnify l (Strict.RWST m) = Strict.RWST $ \r s w ->+ (getEffectRWS #. l (EffectRWS #. (\r' s' -> m r' s' w))) r s+ {-# INLINE magnify #-}
+ src/Control/Monad/Trans/Writer/CPS/Lens.hs view
@@ -0,0 +1,30 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}++module Control.Monad.Trans.Writer.CPS.Lens where++import Control.Lens+import Control.Lens.Internal.Zoom+import Control.Monad.Trans.Writer.CPS.Internal as Strict+import Control.Monad.Writer.CPS as Strict+import Data.Profunctor.Unsafe++-- | Unlike normal Wrapped instances, this doesn't simply peel off the newtype wrapper,+-- as that will expose the hidden CPS w state.+-- Based on code from Control.Lens.Wrapped+instance (Monoid w, Functor m, t ~ Strict.WriterT w' m' a') => Rewrapped (Strict.WriterT w m a) t+instance (Monoid w, Functor m) => Wrapped (Strict.WriterT w m a) where+ type Unwrapped (Strict.WriterT w m a) = m (a, w)+ _Wrapped' = iso Strict.runWriterT Strict.writerT+ {-# INLINE _Wrapped' #-}++-- | The Zoomed instance uses the Strict.Internal constructor to avoid a @Monoid w@ constraint.+-- | Based on code from Control.Lens.Zoomed+type instance Zoomed (Strict.WriterT w m) = FocusingPlus w (Zoomed m)+instance Zoom m n s t => Zoom (Strict.WriterT w m) (Strict.WriterT w n) s t where+ zoom l (Strict.WriterT m) = Strict.WriterT $ \w ->+ zoom (\afb -> unfocusingPlus #. l (FocusingPlus #. afb)) (m w)+ {-# INLINE zoom #-}
+ writer-cps-lens.cabal view
@@ -0,0 +1,32 @@+name: writer-cps-lens+version: 0.1.0.0+synopsis: Lens instances for the stricter CPS WriterT and RWST+description: Control.Lens Wrapped, Magnify and Zoomed instances for the stricter WriterT and RWST from writer-cps-transformers.+homepage: https://github.com/louispan/writer-cps-lens#readme+license: BSD3+license-file: LICENSE+author: Louis Pan, Edward A. Kmett+maintainer: louis@pan.me+copyright: 2017 Louis Pan+category: Control+build-type: Simple+extra-source-files: README.md+cabal-version: >=1.10+tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1++library+ hs-source-dirs: src+ exposed-modules: Control.Monad.Trans.RWS.CPS.Lens+ , Control.Monad.Trans.Writer.CPS.Lens+ build-depends: base < 6+ , writer-cps-transformers >= 0.1.1.2+ , transformers >= 0.4 && < 0.6+ , lens >= 4 && < 5+ , profunctors >= 5 && < 6+ , writer-cps-mtl >= 0.1.1.1+ ghc-options: -Wall+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/louispan/writer-cps-lens