Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy instances for the remaining transformers #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Control/Comonad/Env/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import Prelude
import Control.Comonad (class Comonad, extract)
import Control.Comonad.Trans.Class (class ComonadTrans)
import Control.Extend (class Extend, (<<=))

import Control.Lazy (class Lazy)
import Data.Newtype (class Newtype)
import Data.Traversable (class Traversable, class Foldable, foldl, foldr, foldMap, traverse, sequence)
import Data.Tuple (Tuple(..))
import Data.Newtype (class Newtype)

-- | The environment comonad transformer.
-- |
Expand Down Expand Up @@ -46,6 +46,8 @@ instance comonadEnvT :: Comonad w => Comonad (EnvT e w) where
instance comonadTransEnvT :: ComonadTrans (EnvT e) where
lower (EnvT (Tuple e x)) = x

derive newtype instance lazyEnvT :: (Lazy e, Lazy (w a)) => Lazy (EnvT e w a)

instance foldableEnvT :: Foldable f => Foldable (EnvT e f) where
foldl fn a (EnvT (Tuple _ x)) = foldl fn a x
foldr fn a (EnvT (Tuple _ x)) = foldr fn a x
Expand Down
6 changes: 4 additions & 2 deletions src/Control/Comonad/Store/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import Prelude
import Control.Comonad (class Comonad, extract)
import Control.Comonad.Trans.Class (class ComonadTrans)
import Control.Extend (class Extend, (<<=))

import Data.Tuple (Tuple(..))
import Control.Lazy (class Lazy)
import Data.Newtype (class Newtype)
import Data.Tuple (Tuple(..))

-- | The store comonad transformer.
-- |
Expand All @@ -36,3 +36,5 @@ instance comonadStoreT :: Comonad w => Comonad (StoreT s w) where

instance comonadTransStoreT :: ComonadTrans (StoreT s) where
lower (StoreT (Tuple w s)) = (_ $ s) <$> w

derive newtype instance lazyStoreT :: (Lazy (w (s -> a)), Lazy s) => Lazy (StoreT s w a)
3 changes: 3 additions & 0 deletions src/Control/Comonad/Traced/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Prelude
import Control.Comonad (class Comonad, extract)
import Control.Comonad.Trans.Class (class ComonadTrans)
import Control.Extend (class Extend, (<<=))
import Control.Lazy (class Lazy)
import Data.Newtype (class Newtype)

-- | The cowriter comonad transformer.
Expand Down Expand Up @@ -34,3 +35,5 @@ instance comonadTracedT :: (Comonad w, Monoid t) => Comonad (TracedT t w) where

instance comonadTransTracedT :: Monoid t => ComonadTrans (TracedT t) where
lower (TracedT w) = (\f -> f mempty) <$> w

derive newtype instance lazyTracedT :: Lazy (w (t -> a)) => Lazy (TracedT t w a)
4 changes: 4 additions & 0 deletions src/Control/Monad/Cont/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Control.Monad.Cont.Trans

import Prelude

import Control.Lazy (class Lazy)
import Control.Monad.Cont.Class (class MonadCont, callCC)
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local)
import Control.Monad.State.Class (class MonadState, state)
Expand Down Expand Up @@ -54,6 +55,9 @@ instance monadContT :: Monad m => Monad (ContT r m)
instance monadTransContT :: MonadTrans (ContT r) where
lift m = ContT (\k -> m >>= k)

instance lazyContT :: Lazy (ContT r m a) where
defer f = ContT \k -> case f unit of ContT f' -> f' k

instance monadEffectContT :: MonadEffect m => MonadEffect (ContT r m) where
liftEffect = lift <<< liftEffect

Expand Down
3 changes: 3 additions & 0 deletions src/Control/Monad/Except/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Prelude

import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Lazy (class Lazy)
import Control.Monad.Cont.Class (class MonadCont, callCC)
import Control.Monad.Error.Class (class MonadThrow, class MonadError, throwError, catchError)
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local)
Expand Down Expand Up @@ -101,6 +102,8 @@ instance monadTransExceptT :: MonadTrans (ExceptT e) where
a <- m
pure $ Right a

derive newtype instance lazyExceptT :: Lazy (m (Either e a)) => Lazy (ExceptT e m a)

instance monadEffectExceptT :: MonadEffect m => MonadEffect (ExceptT e m) where
liftEffect = lift <<< liftEffect

Expand Down
4 changes: 4 additions & 0 deletions src/Control/Monad/List/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Prelude

import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Lazy (class Lazy)
import Control.Monad.Rec.Class as MR
import Control.Monad.Trans.Class (class MonadTrans, lift)
import Control.MonadPlus (class MonadPlus)
Expand Down Expand Up @@ -314,6 +315,9 @@ instance monadListT :: Monad f => Monad (ListT f)
instance monadTransListT :: MonadTrans ListT where
lift = fromEffect

instance lazyListT :: Applicative f => Lazy (ListT f a) where
defer f = ListT <<< pure $ Skip (defer f)

instance altListT :: Applicative f => Alt (ListT f) where
alt = concat

Expand Down
3 changes: 3 additions & 0 deletions src/Control/Monad/Maybe/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Prelude

import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Lazy (class Lazy)
import Control.Monad.Cont.Class (class MonadCont, callCC)
import Control.Monad.Error.Class (class MonadThrow, class MonadError, catchError, throwError)
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local)
Expand Down Expand Up @@ -60,6 +61,8 @@ instance monadMaybeT :: Monad m => Monad (MaybeT m)
instance monadTransMaybeT :: MonadTrans MaybeT where
lift = MaybeT <<< liftM1 Just

derive newtype instance lazyMaybeT :: Lazy (m (Maybe a)) => Lazy (MaybeT m a)

instance altMaybeT :: Monad m => Alt (MaybeT m) where
alt (MaybeT m1) (MaybeT m2) = MaybeT do
m <- m1
Expand Down
3 changes: 3 additions & 0 deletions src/Control/Monad/Reader/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Prelude
import Control.Alt (class Alt, (<|>))
import Control.Alternative (class Alternative)
import Control.Apply (lift2)
import Control.Lazy (class Lazy)
import Control.Monad.Cont.Class (class MonadCont, callCC)
import Control.Monad.Error.Class (class MonadThrow, class MonadError, catchError, throwError)
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, asks, local)
Expand Down Expand Up @@ -83,6 +84,8 @@ instance monadPlusReaderT :: MonadPlus m => MonadPlus (ReaderT r m)
instance monadTransReaderT :: MonadTrans (ReaderT r) where
lift = ReaderT <<< const

derive newtype instance lazyReaderT :: Lazy (ReaderT r m a)

instance monadEffectReader :: MonadEffect m => MonadEffect (ReaderT r m) where
liftEffect = lift <<< liftEffect

Expand Down
3 changes: 3 additions & 0 deletions src/Control/Monad/Writer/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Prelude

import Control.Alt (class Alt, (<|>))
import Control.Alternative (class Alternative)
import Control.Lazy (class Lazy)
import Control.Monad.Cont.Class (class MonadCont, callCC)
import Control.Monad.Error.Class (class MonadThrow, class MonadError, catchError, throwError)
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local)
Expand Down Expand Up @@ -93,6 +94,8 @@ instance monadTransWriterT :: Monoid w => MonadTrans (WriterT w) where
a <- m
pure $ Tuple a mempty

derive newtype instance lazyWriterT :: Lazy (m (Tuple a w)) => Lazy (WriterT w m a)

instance monadEffectWriter :: (Monoid w, MonadEffect m) => MonadEffect (WriterT w m) where
liftEffect = lift <<< liftEffect

Expand Down