Skip to content

Commit 4479f43

Browse files
committed
Update for PureScript 0.11
1 parent e3d58a2 commit 4479f43

File tree

6 files changed

+29
-51
lines changed

6 files changed

+29
-51
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
dist: trusty
33
sudo: required
4-
node_js: 6
4+
node_js: stable
55
env:
66
- PATH=$HOME/purescript:$PATH
77
install:

bower.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
"package.json"
2525
],
2626
"dependencies": {
27-
"purescript-catenable-lists": "^3.0.0",
28-
"purescript-exists": "^2.0.0",
29-
"purescript-inject": "^3.0.0",
30-
"purescript-transformers": "^2.0.0",
31-
"purescript-unsafe-coerce": "^2.0.0"
27+
"purescript-catenable-lists": "^4.0.0",
28+
"purescript-exists": "^3.0.0",
29+
"purescript-transformers": "^3.0.0",
30+
"purescript-unsafe-coerce": "^3.0.0"
3231
},
3332
"devDependencies": {
34-
"purescript-console": "^2.0.0"
33+
"purescript-console": "^3.0.0",
34+
"purescript-functors": "^2.0.0"
3535
}
3636
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build --censor-lib --strict",
5+
"build": "pulp build -- --censor-lib --strict",
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^9.0.1",
10-
"purescript-psa": "^0.3.9",
11-
"rimraf": "^2.5.0"
9+
"pulp": "^10.0.4",
10+
"purescript-psa": "^0.5.0-rc.1",
11+
"rimraf": "^2.6.1"
1212
}
1313
}

src/Control/Comonad/Cofree.purs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ unfoldCofree s e n =
7373
-- | functor underlying the cofree comonad.
7474
explore
7575
:: forall f g a b
76-
. (Functor f, Functor g)
76+
. Functor f
77+
=> Functor g
7778
=> (forall x y. f (x -> y) -> g x -> y)
7879
-> Free f (a -> b)
7980
-> Cofree g a
@@ -87,7 +88,9 @@ explore pair m w =
8788

8889
exploreM
8990
:: forall f g a b m
90-
. (Functor f, Functor g, MonadRec m)
91+
. Functor f
92+
=> Functor g
93+
=> MonadRec m
9194
=> (forall x y. f (x -> y) -> g x -> m y)
9295
-> Free f (a -> b)
9396
-> Cofree g a

src/Control/Monad/Free.purs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ module Control.Monad.Free
22
( Free
33
, suspendF
44
, liftF
5-
, liftFI
65
, hoistFree
7-
, injF
86
, foldFree
97
, substFree
108
, runFree
@@ -20,7 +18,6 @@ import Control.Monad.Trans.Class (class MonadTrans)
2018
import Data.CatList (CatList, empty, snoc, uncons)
2119
import Data.Either (Either(..))
2220
import Data.Foldable (class Foldable, foldMap, foldl, foldr)
23-
import Data.Inject (class Inject, inj)
2421
import Data.Maybe (Maybe(..))
2522
import Data.Traversable (class Traversable, traverse)
2623
import Data.Tuple (Tuple(..))
@@ -108,11 +105,6 @@ liftF f = fromView (Bind (unsafeCoerceF f) (pure <<< unsafeCoerceVal))
108105
unsafeCoerceVal :: forall a. Val -> a
109106
unsafeCoerceVal = unsafeCoerce
110107

111-
-- | Lift an action described by the generating type constructor `f` into
112-
-- | `Free g` using `Inject` to go from `f` to `g`.
113-
liftFI :: forall f g. Inject f g => f ~> Free g
114-
liftFI fa = liftF (inj fa)
115-
116108
-- | Suspend a value given the applicative functor `f` into the free monad.
117109
suspendF :: forall f. Applicative f => Free f ~> Free f
118110
suspendF f = fromView (Bind (unsafeCoerceF (pure f)) unsafeCoerceVal)
@@ -128,15 +120,6 @@ suspendF f = fromView (Bind (unsafeCoerceF (pure f)) unsafeCoerceVal)
128120
hoistFree :: forall f g. (f ~> g) -> Free f ~> Free g
129121
hoistFree k = substFree (liftF <<< k)
130122

131-
-- | Embed computations in one `Free` monad as computations in the `Free` monad
132-
-- | for a coproduct type constructor.
133-
-- |
134-
-- | This construction allows us to write computations which are polymorphic in
135-
-- | the particular `Free` monad we use, allowing us to extend the functionality
136-
-- | of our monad later.
137-
injF :: forall f g. Inject f g => Free f ~> Free g
138-
injF = hoistFree inj
139-
140123
-- | Run a free monad with a natural transformation from the type constructor `f`
141124
-- | to the tail-recursive monad `m`. See the `MonadRec` type class for more
142125
-- | details.
@@ -172,7 +155,8 @@ runFree k = go
172155
-- | monad `m`. See the `MonadRec` type class for more details.
173156
runFreeM
174157
:: forall f m a
175-
. (Functor f, MonadRec m)
158+
. Functor f
159+
=> MonadRec m
176160
=> (f (Free f a) -> m (Free f a))
177161
-> Free f a
178162
-> m a

test/Test/Control/Monad/Free/Coproduct.purs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ module Test.Control.Monad.Free.Coproduct where
22

33
import Prelude
44

5-
import Control.Alt ((<|>))
65
import Control.Monad.Eff (Eff)
76
import Control.Monad.Eff.Console (CONSOLE, log)
8-
import Control.Monad.Free (Free, liftF, foldFree, injF)
7+
import Control.Monad.Free (Free, liftF, hoistFree, foldFree)
98

10-
import Data.Functor.Coproduct (Coproduct)
11-
import Data.Inject (prj)
12-
import Data.Maybe (fromJust)
13-
import Data.NaturalTransformation (NaturalTransformation)
14-
15-
import Partial.Unsafe (unsafePartial)
9+
import Data.Functor.Coproduct (Coproduct, coproduct, left, right)
1610

1711
data Teletype1F a = Print1 String a
1812

@@ -40,33 +34,30 @@ type TF = Coproduct Teletype1F (Coproduct Teletype2F Teletype3F)
4034
type T a = Free TF a
4135

4236
r :: T Unit
43-
r = injF (print1 "1")
37+
r = hoistFree left (print1 "1")
4438

4539
s :: T Unit
46-
s = injF (print2 "2")
40+
s = hoistFree (right <<< left) (print2 "2")
4741

4842
t :: T Unit
49-
t = injF (print3 "3")
43+
t = hoistFree (right <<< right) (print3 "3")
5044

5145
u :: T Unit
5246
u = r *> s *> t
5347

54-
teletype1N :: forall eff. NaturalTransformation Teletype1F (Eff (console :: CONSOLE | eff))
48+
teletype1N :: forall eff. Teletype1F ~> Eff (console :: CONSOLE | eff)
5549
teletype1N (Print1 x a) = const a <$> log ("teletype1: " <> x)
5650

57-
teletype2N :: forall eff. NaturalTransformation Teletype2F (Eff (console :: CONSOLE | eff))
51+
teletype2N :: forall eff. Teletype2F ~> Eff (console :: CONSOLE | eff)
5852
teletype2N (Print2 x a) = const a <$> log ("teletype2: " <> x)
5953

60-
teletype3N :: forall eff. NaturalTransformation Teletype3F (Eff (console :: CONSOLE | eff))
54+
teletype3N :: forall eff. Teletype3F ~> Eff (console :: CONSOLE | eff)
6155
teletype3N (Print3 x a) = const a <$> log ("teletype3: " <> x)
6256

63-
tN :: forall eff. NaturalTransformation TF (Eff (console :: CONSOLE | eff))
64-
tN fa = unsafePartial $
65-
fromJust $ (teletype1N <$> prj fa) <|>
66-
(teletype2N <$> prj fa) <|>
67-
(teletype3N <$> prj fa)
57+
tN :: forall eff. TF ~> Eff (console :: CONSOLE | eff)
58+
tN = coproduct teletype1N $ coproduct teletype2N teletype3N
6859

69-
run :: forall eff. NaturalTransformation T (Eff (console :: CONSOLE | eff))
60+
run :: forall eff. T ~> Eff (console :: CONSOLE | eff)
7061
run = foldFree tN
7162

7263
main :: forall eff. Eff (console :: CONSOLE | eff) Unit

0 commit comments

Comments
 (0)