Skip to content

Commit f26bbd4

Browse files
authored
Merge pull request #77 from purescript/bump
Prepare for 2.0 release
2 parents 003779d + 78ff659 commit f26bbd4

File tree

22 files changed

+200
-164
lines changed

22 files changed

+200
-164
lines changed

bower.json

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,12 @@
2424
"package.json"
2525
],
2626
"dependencies": {
27-
"purescript-arrays": "^1.1.0",
27+
"purescript-arrays": "^3.0.0",
2828
"purescript-lazy": "^2.0.0",
29-
"purescript-tailrec": "^2.0.0",
30-
"purescript-unfoldable": "^1.1.0",
31-
"purescript-distributive": "bump",
29+
"purescript-distributive": "^2.0.0",
3230
"purescript-tuples": "^3.0.0"
3331
},
3432
"devDependencies": {
3533
"purescript-console": "^2.0.0"
36-
},
37-
"resolutions": {
38-
"purescript-tuples": "^3.0.0",
39-
"purescript-monoid": "^2.0.0",
40-
"purescript-foldable-traversable": "^2.0.0",
41-
"purescript-st": "^2.0.0",
42-
"purescript-eff": "^2.0.0",
43-
"purescript-control": "^2.0.0",
44-
"purescript-bifunctors": "^2.0.0",
45-
"purescript-invariant": "^2.0.0",
46-
"purescript-maybe": "^2.0.0",
47-
"purescript-prelude": "^2.1.0"
4834
}
4935
}

src/Control/Comonad/Env/Class.purs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ import Control.Comonad.Env.Trans (EnvT(..))
77

88
import Data.Tuple (Tuple(..), fst)
99

10-
-- | The `ComonadEnv` type class represents those monads which support a global environment via
11-
-- | `ask` and `local`.
10+
-- | The `ComonadEnv` type class represents those comonads which support a
11+
-- | global environment that can be provided via the `ask` function.
1212
-- |
13-
-- | - `ask` reads the current environment from the context.
14-
-- | - `local` changes the value of the global environment.
13+
-- | An implementation is provided for `EnvT`.
14+
class Comonad w <= ComonadAsk e w | w -> e where
15+
ask :: forall a. w a -> e
16+
17+
-- | Get a value which depends on the environment.
18+
asks :: forall e1 e2 w. ComonadEnv e1 w => (e1 -> e2) -> w e1 -> e2
19+
asks f x = f (ask x)
20+
21+
-- | The `ComonadEnv` type class extends `ComonadAsk` with a function
22+
-- | `local f x` that allows the value of the local context to be modified for
23+
-- | the duration of the execution of action `x`.
1524
-- |
1625
-- | An implementation is provided for `EnvT`.
1726
-- |
@@ -20,19 +29,18 @@ import Data.Tuple (Tuple(..), fst)
2029
-- | - `ask (local f x) = f (ask x)`
2130
-- | - `extract (local _ x) = extract a`
2231
-- | - `extend g (local f x) = extend (g <<< local f) x`
23-
class Comonad w <= ComonadEnv e w | w -> e where
24-
ask :: forall a. w a -> e
32+
class ComonadAsk e w <= ComonadEnv e w | w -> e where
2533
local :: forall a. (e -> e) -> w a -> w a
2634

27-
-- | Get a value which depends on the environment.
28-
asks :: forall e1 e2 w. ComonadEnv e1 w => (e1 -> e2) -> w e1 -> e2
29-
asks f x = f (ask x)
35+
instance comonadAskTuple :: ComonadAsk e (Tuple e) where
36+
ask = fst
3037

3138
instance comonadEnvTuple :: ComonadEnv e (Tuple e) where
32-
ask = fst
3339
local f (Tuple x y) = Tuple (f x) y
3440

35-
instance comonadEnvEnvT :: Comonad w => ComonadEnv e (EnvT e w) where
41+
instance comonadAskEnvT :: Comonad w => ComonadAsk e (EnvT e w) where
3642
ask (EnvT x) = fst x
43+
44+
instance comonadEnvEnvT :: Comonad w => ComonadEnv e (EnvT e w) where
3745
local f (EnvT x) = EnvT case x of
3846
Tuple x y -> Tuple (f x) y

src/Control/Comonad/Env/Trans.purs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ module Control.Comonad.Env.Trans where
55
import Prelude
66

77
import Control.Comonad (class Comonad, extract)
8-
import Control.Comonad.Trans (class ComonadTrans)
8+
import Control.Comonad.Trans.Class (class ComonadTrans)
99
import Control.Extend (class Extend, (<<=))
1010

1111
import Data.Tuple (Tuple(..))
12+
import Data.Newtype (class Newtype)
1213

1314
-- | The environment comonad transformer.
1415
-- |
@@ -30,6 +31,8 @@ withEnvT f (EnvT (Tuple e x)) = EnvT $ Tuple (f e) x
3031
mapEnvT :: forall e w1 w2 a b. (w1 a -> w2 b) -> EnvT e w1 a -> EnvT e w2 b
3132
mapEnvT f (EnvT (Tuple e x)) = EnvT $ Tuple e (f x)
3233

34+
derive instance newtypeEnvT :: Newtype (EnvT e w a) _
35+
3336
instance functorEnvT :: Functor w => Functor (EnvT e w) where
3437
map f (EnvT (Tuple e x)) = EnvT $ Tuple e (f <$> x)
3538

src/Control/Comonad/Store/Trans.purs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ module Control.Comonad.Store.Trans where
55
import Prelude
66

77
import Control.Comonad (class Comonad, extract)
8-
import Control.Comonad.Trans (class ComonadTrans)
8+
import Control.Comonad.Trans.Class (class ComonadTrans)
99
import Control.Extend (class Extend, (<<=))
1010

1111
import Data.Tuple (Tuple(..))
12+
import Data.Newtype (class Newtype)
1213

1314
-- | The store comonad transformer.
1415
-- |
@@ -22,6 +23,8 @@ newtype StoreT s w a = StoreT (Tuple (w (s -> a)) s)
2223
runStoreT :: forall s w a. StoreT s w a -> Tuple (w (s -> a)) s
2324
runStoreT (StoreT s) = s
2425

26+
derive instance newtypeStoreT :: Newtype (StoreT s w a) _
27+
2528
instance functorStoreT :: Functor w => Functor (StoreT s w) where
2629
map f (StoreT (Tuple w s)) = StoreT $ Tuple ((\h -> h >>> f) <$> w) s
2730

src/Control/Comonad/Traced/Trans.purs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ module Control.Comonad.Traced.Trans where
55
import Prelude
66

77
import Control.Comonad (class Comonad, extract)
8-
import Control.Comonad.Trans (class ComonadTrans)
8+
import Control.Comonad.Trans.Class (class ComonadTrans)
99
import Control.Extend (class Extend, (<<=))
1010

1111
import Data.Monoid (class Monoid, mempty)
12+
import Data.Newtype (class Newtype)
1213

1314
-- | The cowriter comonad transformer.
1415
-- |
@@ -22,6 +23,8 @@ newtype TracedT t w a = TracedT (w (t -> a))
2223
runTracedT :: forall w a t. TracedT t w a -> w (t -> a)
2324
runTracedT (TracedT w) = w
2425

26+
derive instance newtypeTracedT :: Newtype (TracedT t w a) _
27+
2528
instance functorTracedT :: Functor w => Functor (TracedT t w) where
2629
map f (TracedT w) = TracedT ((\g t -> f $ g t) <$> w)
2730

src/Control/Comonad/Trans.purs renamed to src/Control/Comonad/Trans/Class.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- | This module defines the `ComonadTrans` type class of _comonad transformers_.
22

3-
module Control.Comonad.Trans where
3+
module Control.Comonad.Trans.Class where
44

55
import Control.Comonad (class Comonad)
66

src/Control/Monad/Cont/Trans.purs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
module Control.Monad.Cont.Trans
44
( ContT(..), runContT, mapContT, withContT
5-
, module Control.Monad.Trans
5+
, module Control.Monad.Trans.Class
66
, module Control.Monad.Cont.Class
77
) where
88

99
import Prelude
1010

1111
import Control.Monad.Cont.Class (class MonadCont, callCC)
1212
import Control.Monad.Eff.Class (class MonadEff, liftEff)
13-
import Control.Monad.Reader.Class (class MonadReader, ask, local)
13+
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local)
1414
import Control.Monad.State.Class (class MonadState, state)
15-
import Control.Monad.Trans (class MonadTrans, lift)
15+
import Control.Monad.Trans.Class (class MonadTrans, lift)
16+
17+
import Data.Newtype (class Newtype)
1618

1719
-- | The CPS monad transformer.
1820
-- |
@@ -31,6 +33,8 @@ mapContT f (ContT m) = ContT (\k -> f (m k))
3133
withContT :: forall r m a b. ((b -> m r) -> (a -> m r)) -> ContT r m a -> ContT r m b
3234
withContT f (ContT m) = ContT (\k -> m (f k))
3335

36+
derive instance newtypeContT :: Newtype (ContT r m a) _
37+
3438
instance monadContContT :: Monad m => MonadCont (ContT r m) where
3539
callCC f = ContT (\k -> case f (\a -> ContT (\_ -> k a)) of ContT f' -> f' k)
3640

@@ -54,8 +58,10 @@ instance monadTransContT :: MonadTrans (ContT r) where
5458
instance monadEffContT :: MonadEff eff m => MonadEff eff (ContT r m) where
5559
liftEff = lift <<< liftEff
5660

57-
instance monadReaderContT :: MonadReader r1 m => MonadReader r1 (ContT r m) where
61+
instance monadAskContT :: MonadAsk r1 m => MonadAsk r1 (ContT r m) where
5862
ask = lift ask
63+
64+
instance monadReaderContT :: MonadReader r1 m => MonadReader r1 (ContT r m) where
5965
local f (ContT c) = ContT \k -> do
6066
r <- ask
6167
local f (c (local (const (r :: r1)) <<< k))

src/Control/Monad/Except/Trans.purs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Control.Monad.Except.Trans
44
( ExceptT(..), runExceptT, withExceptT, mapExceptT, except
5-
, module Control.Monad.Trans
5+
, module Control.Monad.Trans.Class
66
, module Control.Monad.Error.Class
77
) where
88

@@ -13,18 +13,18 @@ import Control.Alternative (class Alternative)
1313
import Control.Monad.Cont.Class (class MonadCont, callCC)
1414
import Control.Monad.Eff.Class (class MonadEff, liftEff)
1515
import Control.Monad.Error.Class (class MonadError, throwError, catchError)
16-
import Control.Monad.Reader.Class (class MonadReader, local, ask)
16+
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader, ask, local)
1717
import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..))
18-
import Control.Monad.RWS.Class (class MonadRWS)
1918
import Control.Monad.State.Class (class MonadState, state)
20-
import Control.Monad.Trans (class MonadTrans, lift)
21-
import Control.Monad.Writer.Class (class MonadWriter, pass, listen, writer)
19+
import Control.Monad.Trans.Class (class MonadTrans, lift)
20+
import Control.Monad.Writer.Class (class MonadWriter, class MonadTell, pass, listen, tell)
2221
import Control.MonadPlus (class MonadPlus)
2322
import Control.MonadZero (class MonadZero)
2423
import Control.Plus (class Plus)
2524

2625
import Data.Either (Either(..), either)
2726
import Data.Monoid (class Monoid, mempty)
27+
import Data.Newtype (class Newtype)
2828
import Data.Tuple (Tuple(..))
2929

3030
-- | A monad transformer which adds exceptions to other monads, in the same way
@@ -52,16 +52,15 @@ mapExceptT f (ExceptT m) = ExceptT (f m)
5252
except :: forall e m a. Applicative m => Either e a -> ExceptT e m a
5353
except = ExceptT <<< pure
5454

55+
derive instance newtypeExceptT :: Newtype (ExceptT e m a) _
56+
5557
instance functorExceptT :: Functor m => Functor (ExceptT e m) where
5658
map f = mapExceptT (map (map f))
5759

58-
instance applyExceptT :: Apply m => Apply (ExceptT e m) where
59-
apply (ExceptT f) (ExceptT x) =
60-
let f' = apply <$> f
61-
x' = f' <*> x
62-
in ExceptT x'
60+
instance applyExceptT :: Monad m => Apply (ExceptT e m) where
61+
apply = ap
6362

64-
instance applicativeExceptT :: Applicative m => Applicative (ExceptT e m) where
63+
instance applicativeExceptT :: Monad m => Applicative (ExceptT e m) where
6564
pure = ExceptT <<< pure <<< Right
6665

6766
instance bindExceptT :: Monad m => Bind (ExceptT e m) where
@@ -116,15 +115,19 @@ instance monadErrorExceptT :: Monad m => MonadError e (ExceptT e m) where
116115
catchError (ExceptT m) k =
117116
ExceptT (m >>= either (\a -> case k a of ExceptT b -> b) (pure <<< Right))
118117

119-
instance monadReaderExceptT :: MonadReader r m => MonadReader r (ExceptT e m) where
118+
instance monadAskExceptT :: MonadAsk r m => MonadAsk r (ExceptT e m) where
120119
ask = lift ask
120+
121+
instance monadReaderExceptT :: MonadReader r m => MonadReader r (ExceptT e m) where
121122
local f = mapExceptT (local f)
122123

123124
instance monadStateExceptT :: MonadState s m => MonadState s (ExceptT e m) where
124125
state f = lift (state f)
125126

127+
instance monadTellExceptT :: MonadTell w m => MonadTell w (ExceptT e m) where
128+
tell = lift <<< tell
129+
126130
instance monadWriterExceptT :: MonadWriter w m => MonadWriter w (ExceptT e m) where
127-
writer wd = lift (writer wd)
128131
listen = mapExceptT \m -> do
129132
Tuple a w <- listen m
130133
pure $ (\r -> Tuple r w) <$> a
@@ -133,5 +136,3 @@ instance monadWriterExceptT :: MonadWriter w m => MonadWriter w (ExceptT e m) wh
133136
pure case a of
134137
Left e -> Tuple (Left e) id
135138
Right (Tuple r f) -> Tuple (Right r) f
136-
137-
instance monadRWSExceptT :: MonadRWS r w s m => MonadRWS r w s (ExceptT e m)

src/Control/Monad/List/Trans.purs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ module Control.Monad.List.Trans
2828
, wrapLazy
2929
, zipWith
3030
, zipWith'
31-
, module Control.Monad.Trans
31+
, module Control.Monad.Trans.Class
3232
) where
3333

3434
import Prelude
3535

3636
import Control.Alt (class Alt)
3737
import Control.Alternative (class Alternative)
3838
import Control.Monad.Eff.Class (class MonadEff, liftEff)
39-
import Control.Monad.Trans (class MonadTrans, lift)
39+
import Control.Monad.Trans.Class (class MonadTrans, lift)
4040
import Control.MonadPlus (class MonadPlus)
4141
import Control.MonadZero (class MonadZero)
4242
import Control.Plus (class Plus)
4343

4444
import Data.Lazy (Lazy, defer, force)
4545
import Data.Maybe (Maybe(..), fromMaybe)
4646
import Data.Monoid (class Monoid)
47+
import Data.Newtype (class Newtype)
4748
import Data.Tuple (Tuple(..), fst, snd)
4849
import Data.Unfoldable (class Unfoldable)
4950

@@ -52,7 +53,7 @@ import Data.Unfoldable (class Unfoldable)
5253
-- | This monad transformer extends the base monad with _non-determinism_.
5354
-- | That is, the transformed monad supports the same effects as the base monad
5455
-- | but with multiple return values.
55-
data ListT f a = ListT (f (Step a (ListT f a)))
56+
newtype ListT f a = ListT (f (Step a (ListT f a)))
5657

5758
-- | The result of a single step in a `ListT` computation. Either:
5859
-- |
@@ -215,7 +216,7 @@ scanl f b l = unfold g (Tuple b l)
215216
where
216217
g (Tuple b' (ListT l')) = h <$> l'
217218
where
218-
h (Yield a s) = let b'' = f b a in Just $ Tuple (Tuple b'' (force s)) b''
219+
h (Yield a s) = let b'' = f b' a in Just $ Tuple (Tuple b'' (force s)) b'
219220
h (Skip s) = Just $ Tuple (Tuple b' (force s)) b'
220221
h Done = Nothing
221222

@@ -237,6 +238,8 @@ zipWith f = zipWith' g
237238
where
238239
g a b = pure $ f a b
239240

241+
derive instance newtypeListT :: Newtype (ListT f a) _
242+
240243
instance semigroupListT :: Applicative f => Semigroup (ListT f a) where
241244
append = concat
242245

0 commit comments

Comments
 (0)