Skip to content

Commit 7aa0e51

Browse files
authored
Merge pull request #5 from purescript-contrib/bump
Update dependencies & add build
2 parents 79732dc + 0759c62 commit 7aa0e51

File tree

8 files changed

+84
-128
lines changed

8 files changed

+84
-128
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
output
2-
bower_components
1+
/.*
2+
!/.gitignore
3+
!/.travis.yml
4+
/bower_components/
5+
/node_modules/
6+
/output/

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: 6
5+
install:
6+
- npm install -g bower
7+
- npm install
8+
- bower install
9+
script:
10+
- npm run -s build
11+
after_success:
12+
- >-
13+
test $TRAVIS_TAG &&
14+
echo $GITHUB_TOKEN | pulp login &&
15+
echo y | pulp publish --no-push

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# purescript-freet
22

3-
[![Latest release](http://img.shields.io/bower/v/purescript-freet.svg)](https://github.com/purescript-contrib/purescript-freet/releases)
3+
[![Latest release](http://img.shields.io/github/release/purescript-contrib/purescript-freet.svg)](https://github.com/purescript-contrib/purescript-freet/releases)
4+
[![Build Status](https://travis-ci.org/purescript-contrib/purescript-freet.svg?branch=master)](https://travis-ci.org/purescript-contrib/purescript-freet)
45
[![Maintainer: paf31](https://img.shields.io/badge/maintainer-paf31-lightgrey.svg)](http://github.com/paf31)
56
[![Pursuit](http://pursuit.purescript.org/packages/purescript-freet/badge)](http://pursuit.purescript.org/packages/purescript-freet/)
67

7-
Free monad transformers
8+
Free monad transformers.
89

9-
- [Module Documentation](docs/Control/Monad/Free/Trans.md)
10-
- [Example](test/Main.purs)
10+
## Installation
11+
12+
```
13+
bower install purescript-freet
14+
```
15+
16+
## Documentation
17+
18+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-freet).

bower.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"name": "purescript-freet",
3-
"moduleType": [
4-
"node"
5-
],
63
"ignore": [
74
"**/.*",
8-
"node_modules",
95
"bower_components",
10-
"output"
6+
"node_modules",
7+
"output",
8+
"test",
9+
"bower.json",
10+
"package.json"
1111
],
1212
"license": "MIT",
1313
"repository": {
1414
"type": "git",
1515
"url": "git://github.com/paf31/purescript-freet.git"
1616
},
1717
"dependencies": {
18-
"purescript-console": "^1.0.0-rc.1",
19-
"purescript-control": "^1.0.0-rc.1",
20-
"purescript-tailrec": "^1.0.0-rc.1",
21-
"purescript-transformers": "^1.0.0-rc.1",
22-
"purescript-exists": "^1.0.0-rc.1"
18+
"purescript-console": "^2.0.0",
19+
"purescript-control": "^2.0.0",
20+
"purescript-tailrec": "^2.0.0",
21+
"purescript-transformers": "^2.0.1",
22+
"purescript-exists": "^2.0.0"
2323
}
2424
}

docs/Control/Monad/Free/Trans.md

Lines changed: 0 additions & 80 deletions
This file was deleted.

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "pulp build --censor-lib --strict"
6+
},
7+
"devDependencies": {
8+
"pulp": "^9.0.1",
9+
"purescript-psa": "^0.3.9",
10+
"purescript": "^0.10.1",
11+
"rimraf": "^2.5.4"
12+
}
13+
}

src/Control/Monad/Free/Trans.purs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- | This module defines a stack-safe implementation of the _free monad transformer_.
22

33
module Control.Monad.Free.Trans
4-
( FreeT()
4+
( FreeT
55
, freeT
66
, liftFreeT
77
, hoistFreeT
@@ -13,13 +13,12 @@ module Control.Monad.Free.Trans
1313

1414
import Prelude
1515

16-
import Data.Exists (Exists(), mkExists, runExists)
17-
import Data.Either (Either(..))
1816
import Data.Bifunctor (bimap)
17+
import Data.Either (Either(..))
18+
import Data.Exists (Exists, mkExists, runExists)
1919

20-
import Control.Bind ((<=<))
21-
import Control.Monad.Rec.Class (class MonadRec, tailRecM)
22-
import Control.Monad.Trans (class MonadTrans)
20+
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM)
21+
import Control.Monad.Trans.Class (class MonadTrans)
2322

2423
-- | Instead of implementing `bind` directly, we capture the bind using this data structure, to
2524
-- | evaluate later.
@@ -40,16 +39,16 @@ freeT = FreeT
4039
resume :: forall f m a. (Functor f, MonadRec m) => FreeT f m a -> m (Either a (f (FreeT f m a)))
4140
resume = tailRecM go
4241
where
43-
go :: FreeT f m a -> m (Either (FreeT f m a) (Either a (f (FreeT f m a))))
44-
go (FreeT f) = map Right (f unit)
42+
go :: FreeT f m a -> m (Step (FreeT f m a) (Either a (f (FreeT f m a))))
43+
go (FreeT f) = map Done (f unit)
4544
go (Bind e) = runExists (\(Bound bound f) ->
4645
case bound unit of
4746
FreeT m -> do
4847
e <- m unit
4948
case e of
50-
Left a -> pure (Left (f a))
51-
Right fc -> pure (Right (Right (map (\h -> h >>= f) fc)))
52-
Bind e1 -> runExists (\(Bound m1 f1) -> pure (Left (bind (m1 unit) (\z -> f1 z >>= f)))) e1) e
49+
Left a -> pure (Loop (f a))
50+
Right fc -> pure (Done (Right (map (\h -> h >>= f) fc)))
51+
Bind e1 -> runExists (\(Bound m1 f1) -> pure (Loop (bind (m1 unit) (\z -> f1 z >>= f)))) e1) e
5352

5453
instance functorFreeT :: (Functor f, Functor m) => Functor (FreeT f m) where
5554
map f (FreeT m) = FreeT \_ -> map (bimap f (map (map f))) (m unit)
@@ -73,35 +72,32 @@ instance monadTransFreeT :: (Functor f) => MonadTrans (FreeT f) where
7372
instance monadRecFreeT :: (Functor f, Monad m) => MonadRec (FreeT f m) where
7473
tailRecM f = go
7574
where
76-
go s = do
77-
e <- f s
78-
case e of
79-
Left s1 -> go s1
80-
Right a -> pure a
75+
go s =
76+
f s >>= case _ of
77+
Loop s1 -> go s1
78+
Done a -> pure a
8179

8280
-- | Lift an action from the functor `f` to a `FreeT` action.
8381
liftFreeT :: forall f m a. (Functor f, Monad m) => f a -> FreeT f m a
8482
liftFreeT fa = FreeT \_ -> pure (Right (map pure fa))
8583

8684
-- | Change the underlying `Monad` for a `FreeT` action.
87-
hoistFreeT :: forall f m n a. (Functor f, Functor n) => (forall b. m b -> n b) -> FreeT f m a -> FreeT f n a
85+
hoistFreeT :: forall f m n a. (Functor f, Functor n) => (m ~> n) -> FreeT f m a -> FreeT f n a
8886
hoistFreeT = bimapFreeT id
8987

9088
-- | Change the base functor `f` for a `FreeT` action.
91-
interpret :: forall f g m a. (Functor f, Functor m) => (forall b. f b -> g b) -> FreeT f m a -> FreeT g m a
89+
interpret :: forall f g m a. (Functor f, Functor m) => (f ~> g) -> FreeT f m a -> FreeT g m a
9290
interpret nf = bimapFreeT nf id
9391

9492
-- | Change the base functor `f` and the underlying `Monad` for a `FreeT` action.
95-
bimapFreeT :: forall f g m n a. (Functor f, Functor n) => (forall b. f b -> g b) -> (forall b. m b -> n b) -> FreeT f m a -> FreeT g n a
93+
bimapFreeT :: forall f g m n a. (Functor f, Functor n) => (f ~> g) -> (m ~> n) -> FreeT f m a -> FreeT g n a
9694
bimapFreeT nf nm (Bind e) = runExists (\(Bound a f) -> bound (bimapFreeT nf nm <<< a) (bimapFreeT nf nm <<< f)) e
9795
bimapFreeT nf nm (FreeT m) = FreeT \_ -> map (nf <<< map (bimapFreeT nf nm)) <$> nm (m unit)
9896

9997
-- | Run a `FreeT` computation to completion.
10098
runFreeT :: forall f m a. (Functor f, MonadRec m) => (f (FreeT f m a) -> m (FreeT f m a)) -> FreeT f m a -> m a
10199
runFreeT interp = tailRecM (go <=< resume)
102100
where
103-
go :: Either a (f (FreeT f m a)) -> m (Either (FreeT f m a) a)
104-
go (Left a) = pure (Right a)
105-
go (Right fc) = do
106-
c <- interp fc
107-
pure (Left c)
101+
go :: Either a (f (FreeT f m a)) -> m (Step (FreeT f m a) a)
102+
go (Left a) = pure (Done a)
103+
go (Right fc) = Loop <$> interp fc

test/Main.purs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ module Test.Main where
22

33
import Prelude
44

5-
import Control.Apply
6-
import Control.Monad.Eff
7-
import Control.Monad.Eff.Class
8-
import Control.Monad.Eff.Console
9-
import Control.Monad.Trans
10-
import Control.Monad.Free.Trans
11-
import Control.Monad.Rec.Class
5+
import Control.Monad.Eff (Eff)
6+
import Control.Monad.Eff.Class (liftEff)
7+
import Control.Monad.Eff.Console (CONSOLE, log)
8+
import Control.Monad.Free.Trans (FreeT, runFreeT, liftFreeT)
9+
import Control.Monad.Rec.Class (forever)
10+
import Control.Monad.Trans.Class (lift)
1211

1312
data TeletypeF a
1413
= WriteLine String a
@@ -23,7 +22,7 @@ type Teletype = FreeT TeletypeF
2322
writeLine :: forall m. Monad m => String -> FreeT TeletypeF m Unit
2423
writeLine s = liftFreeT (WriteLine s unit)
2524

26-
readLine :: forall m. Monad m => FreeT TeletypeF m String
25+
readLine :: forall m. Monad m => FreeT TeletypeF m String
2726
readLine = liftFreeT (ReadLine id)
2827

2928
mockTeletype :: forall a eff. Teletype (Eff (console :: CONSOLE | eff)) a -> Eff (console :: CONSOLE | eff) a
@@ -35,6 +34,7 @@ mockTeletype = runFreeT interp
3534
interp (ReadLine k) = do
3635
pure (k "Fake input")
3736

37+
main :: forall eff. Eff (console :: CONSOLE | eff) Unit
3838
main = mockTeletype $ forever do
3939
lift $ log "Enter some input:"
4040
s <- readLine

0 commit comments

Comments
 (0)