Skip to content

Commit 7cefee5

Browse files
authored
Merge pull request #97 from purescript/compiler/0.12
Updates for 0.12
2 parents e1e3fd0 + 37d5b35 commit 7cefee5

File tree

12 files changed

+87
-90
lines changed

12 files changed

+87
-90
lines changed

LICENSE

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
Copyright (c) 2014 Eric Thul
1+
Copyright 2018 PureScript
22

3-
Permission is hereby granted, free of charge, to any person obtaining a
4-
copy of this software and associated documentation files (the
5-
"Software"), in the Software without restriction, including without
6-
limitation the rights to use, copy, modify, merge, publish, distribute,
7-
sublicense, and/or sell copies of the Software, and to permit persons to
8-
whom the Software is furnished to do so, subject to the following
9-
conditions:
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
105

11-
The above copyright notice and this permission notice shall be included
12-
in all copies or substantial portions of the Software.
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
138

14-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation and/or
11+
other materials provided with the distribution.
12+
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bower.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"name": "purescript-free",
33
"homepage": "https://github.com/purescript/purescript-free",
4-
"description": "Free, Cofree, Yoneda, Coyoneda, Trampoline",
54
"authors": [
65
"Eric Thul <[email protected]>",
76
"Brian McKenna <[email protected]>",
87
"John A. De Goes <[email protected]> (http://degoes.net)",
98
"Gary Burgess <[email protected]>",
109
"Phil Freeman <[email protected]>"
1110
],
12-
"license": "MIT",
11+
"license": "BSD-3-Clause",
1312
"repository": {
1413
"type": "git",
1514
"url": "git://github.com/purescript/purescript-free.git"
@@ -24,14 +23,23 @@
2423
"package.json"
2524
],
2625
"dependencies": {
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",
31-
"purescript-control": "^3.0.0"
26+
"purescript-catenable-lists": "^5.0.0",
27+
"purescript-control": "^4.0.0",
28+
"purescript-distributive": "^4.0.0",
29+
"purescript-either": "^4.0.0",
30+
"purescript-exists": "^4.0.0",
31+
"purescript-foldable-traversable": "^4.0.0",
32+
"purescript-invariant": "^4.0.0",
33+
"purescript-lazy": "^4.0.0",
34+
"purescript-maybe": "^4.0.0",
35+
"purescript-prelude": "^4.0.0",
36+
"purescript-tailrec": "^4.0.0",
37+
"purescript-transformers": "^4.0.0",
38+
"purescript-tuples": "^5.0.0",
39+
"purescript-unsafe-coerce": "^4.0.0"
3240
},
3341
"devDependencies": {
34-
"purescript-console": "^3.0.0",
35-
"purescript-functors": "^2.0.0"
42+
"purescript-console": "^4.0.0",
43+
"purescript-functors": "^3.0.0"
3644
}
3745
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^10.0.4",
10-
"purescript-psa": "^0.5.0-rc.1",
11-
"rimraf": "^2.6.1"
9+
"pulp": "^12.2.x",
10+
"purescript-psa": "^0.6.x",
11+
"rimraf": "^2.6.2"
1212
}
1313
}

src/Control/Comonad/Cofree.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ instance foldableCofree :: Foldable f => Foldable (Cofree f) where
153153
go fa = f (head fa) <> (foldMap go (tail fa))
154154

155155
instance traversableCofree :: Traversable f => Traversable (Cofree f) where
156-
sequence = traverse id
156+
sequence = traverse identity
157157
traverse f = loop
158158
where
159159
loop ta = mkCofree <$> f (head ta) <*> (traverse loop (tail ta))

src/Control/Monad/Free.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ instance traversableFree :: Traversable f => Traversable (Free f) where
109109
go = resume >>> case _ of
110110
Left fa -> join <<< liftF <$> traverse go fa
111111
Right a -> pure <$> f a
112-
sequence tma = traverse id tma
112+
sequence tma = traverse identity tma
113113

114114
-- | Lift an impure value described by the generating type constructor `f` into
115115
-- | the free monad.

src/Control/Monad/Trampoline.purs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,29 @@
55
module Control.Monad.Trampoline
66
( Trampoline
77
, done
8-
, suspend
9-
, delay'
108
, delay
119
, runTrampoline
1210
) where
1311

1412
import Prelude
1513

16-
import Control.Monad.Free (Free, liftF, runFree, suspendF)
14+
import Control.Monad.Free (Free, liftF, runFree)
1715

18-
import Data.Lazy (Lazy, force, defer)
1916

2017
-- | The `Trampoline` monad
2118
-- |
2219
-- | A computation of type `Trampoline a` consists of zero or more lazy
2320
-- | suspensions before a value is returned.
24-
type Trampoline = Free Lazy
21+
type Trampoline = Free ((->) Unit)
2522

2623
-- | Return a value immediately
2724
done :: forall a. a -> Trampoline a
2825
done = pure
2926

30-
-- | Suspend a computation by one step.
31-
suspend :: forall a. Trampoline a -> Trampoline a
32-
suspend = suspendF
33-
34-
-- | Use the `Trampoline` monad to represent a `Lazy` value.
35-
delay' :: forall a. Lazy a -> Trampoline a
36-
delay' = liftF
37-
3827
-- | Use the `Trampoline` monad to represent the delayed evaluation of a value.
3928
delay :: forall a. (Unit -> a) -> Trampoline a
40-
delay = delay' <<< defer
29+
delay = liftF
4130

4231
-- | Run a computation in the `Trampoline` monad.
4332
runTrampoline :: forall a. Trampoline a -> a
44-
runTrampoline = runFree force
33+
runTrampoline = runFree (_ $ unit)

src/Data/Coyoneda.purs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ data CoyonedaF f a i = CoyonedaF (i -> a) (f i)
4040
-- | hoistCoyoneda nat`:
4141
-- | ```purescript
4242
-- | lowerCoyoneda <<< hoistCoyoneda nat <<< liftCoyoneda $ fi
43-
-- | = lowerCoyoneda (hoistCoyoneda nat (Coyoneda $ mkExists $ CoyonedaF id fi)) (by definition of liftCoyoneda)
44-
-- | = lowerCoyoneda (coyoneda id (nat fi)) (by definition of hoistCoyoneda)
45-
-- | = unCoyoneda map (coyoneda id (nat fi)) (by definition of lowerCoyoneda)
46-
-- | = unCoyoneda map (Coyoneda $ mkExists $ CoyonedaF id (nat fi)) (by definition of coyoneda)
47-
-- | = map id (nat fi) (by definition of unCoyoneda)
43+
-- | = lowerCoyoneda (hoistCoyoneda nat (Coyoneda $ mkExists $ CoyonedaF identity fi)) (by definition of liftCoyoneda)
44+
-- | = lowerCoyoneda (coyoneda identity (nat fi)) (by definition of hoistCoyoneda)
45+
-- | = unCoyoneda map (coyoneda identity (nat fi)) (by definition of lowerCoyoneda)
46+
-- | = unCoyoneda map (Coyoneda $ mkExists $ CoyonedaF identity (nat fi)) (by definition of coyoneda)
47+
-- | = map identity (nat fi) (by definition of unCoyoneda)
4848
-- | = nat fi (since g is a Functor)
4949
-- | ```
5050
newtype Coyoneda f a = Coyoneda (Exists (CoyonedaF f a))
@@ -154,15 +154,15 @@ unCoyoneda f (Coyoneda e) = runExists (\(CoyonedaF k fi) -> f k fi) e
154154
-- | = liftCoyoneda <<< unCoyoneda map $ (Coyoneda e)
155155
-- | = liftCoyonead (runExists (\(CoyonedaF k fi) -> map k fi) e)
156156
-- | = liftCoyonead (Coyoneda e)
157-
-- | = coyoneda id (Coyoneda e)
157+
-- | = coyoneda identity (Coyoneda e)
158158
-- | = Coyoneda e
159159
-- | ```
160160
-- | Moreover if `f` is a `Functor` then `liftCoyoneda` is an isomorphism of
161161
-- | functors with inverse `lowerCoyoneda`: we already showed that
162-
-- | `lowerCoyoneda <<< hoistCoyoneda id = lowerCoyoneda` is its left inverse
162+
-- | `lowerCoyoneda <<< hoistCoyoneda identity = lowerCoyoneda` is its left inverse
163163
-- | whenever `f` is a functor.
164164
liftCoyoneda :: forall f. f ~> Coyoneda f
165-
liftCoyoneda = coyoneda id
165+
liftCoyoneda = coyoneda identity
166166

167167
-- | Lower a value of type `Coyoneda f a` to the `Functor` `f`.
168168
lowerCoyoneda :: forall f. Functor f => Coyoneda f ~> f

src/Data/Yoneda.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ instance functorYoneda :: Functor (Yoneda f) where
3636
map f m = Yoneda (\k -> runYoneda m (k <<< f))
3737

3838
instance applyYoneda :: Apply f => Apply (Yoneda f) where
39-
apply (Yoneda f) (Yoneda g) = Yoneda (\k -> f (compose k) <*> g id)
39+
apply (Yoneda f) (Yoneda g) = Yoneda (\k -> f (compose k) <*> g identity)
4040

4141
instance applicativeYoneda :: Applicative f => Applicative (Yoneda f) where
4242
pure = liftYoneda <<< pure
4343

4444
instance bindYoneda :: Bind f => Bind (Yoneda f) where
45-
bind (Yoneda f) g = Yoneda (\k -> f id >>= \a -> runYoneda (g a) k)
45+
bind (Yoneda f) g = Yoneda (\k -> f identity >>= \a -> runYoneda (g a) k)
4646

4747
instance monadYoneda :: Monad f => Monad (Yoneda f)
4848

4949
instance monadTransYoneda :: MonadTrans Yoneda where
5050
lift = liftYoneda
5151

5252
instance extendYoneda :: Extend w => Extend (Yoneda w) where
53-
extend f (Yoneda w) = Yoneda (\k -> k <<< f <<< liftYoneda <<= w id)
53+
extend f (Yoneda w) = Yoneda (\k -> k <<< f <<< liftYoneda <<= w identity)
5454

5555
instance comonadYoneda :: Comonad w => Comonad (Yoneda w) where
5656
extract = extract <<< lowerYoneda
@@ -65,7 +65,7 @@ liftYoneda m = Yoneda (\k -> k <$> m)
6565

6666
-- | Lower a value of type `Yoneda f a` to the type constructor `f`.
6767
lowerYoneda :: forall f a. Yoneda f a -> f a
68-
lowerYoneda (Yoneda k) = k id
68+
lowerYoneda (Yoneda k) = k identity
6969

7070
-- | Use a natural transformation to change the generating type constructor of a
7171
-- | `Yoneda`.

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

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

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, log)
75
import Control.Monad.Free (Free, liftF, hoistFree, foldFree)
8-
96
import Data.Functor.Coproduct (Coproduct, coproduct, left, right)
7+
import Effect (Effect)
8+
import Effect.Console (log)
109

1110
data Teletype1F a = Print1 String a
1211

@@ -45,20 +44,20 @@ t = hoistFree (right <<< right) (print3 "3")
4544
u :: T Unit
4645
u = r *> s *> t
4746

48-
teletype1N :: forall eff. Teletype1F ~> Eff (console :: CONSOLE | eff)
47+
teletype1N :: Teletype1F ~> Effect
4948
teletype1N (Print1 x a) = const a <$> log ("teletype1: " <> x)
5049

51-
teletype2N :: forall eff. Teletype2F ~> Eff (console :: CONSOLE | eff)
50+
teletype2N :: Teletype2F ~> Effect
5251
teletype2N (Print2 x a) = const a <$> log ("teletype2: " <> x)
5352

54-
teletype3N :: forall eff. Teletype3F ~> Eff (console :: CONSOLE | eff)
53+
teletype3N :: Teletype3F ~> Effect
5554
teletype3N (Print3 x a) = const a <$> log ("teletype3: " <> x)
5655

57-
tN :: forall eff. TF ~> Eff (console :: CONSOLE | eff)
56+
tN :: TF ~> Effect
5857
tN = coproduct teletype1N $ coproduct teletype2N teletype3N
5958

60-
run :: forall eff. T ~> Eff (console :: CONSOLE | eff)
59+
run :: T ~> Effect
6160
run = foldFree tN
6261

63-
main :: forall eff. Eff (console :: CONSOLE | eff) Unit
62+
main :: Effect Unit
6463
main = run u

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

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

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, log)
75
import Control.Monad.Free (Free, foldFree, liftF)
8-
9-
import Data.NaturalTransformation (NaturalTransformation)
6+
import Effect (Effect)
7+
import Effect.Console (log)
108

119
-- | Target DSL that we will actually run
1210
data TeletypeF a
@@ -19,13 +17,13 @@ putStrLn :: String -> Teletype Unit
1917
putStrLn s = liftF $ PutStrLn s unit
2018

2119
getLine :: Teletype String
22-
getLine = liftF $ GetLine id
20+
getLine = liftF $ GetLine identity
2321

2422
-- | Interpreter for `Teletype`, producing an effectful output
25-
runTeletype :: forall eff. NaturalTransformation Teletype (Eff (console :: CONSOLE | eff))
23+
runTeletype :: Teletype ~> Effect
2624
runTeletype = foldFree go
2725
where
28-
go :: NaturalTransformation TeletypeF (Eff (console :: CONSOLE | eff))
26+
go :: TeletypeF ~> Effect
2927
go (PutStrLn s next) = log s $> next
3028
go (GetLine k) = pure (k "fake input")
3129

@@ -37,7 +35,7 @@ data InitialF a
3735
type Initial = Free InitialF
3836

3937
greet :: Initial String
40-
greet = liftF $ Greet id
38+
greet = liftF $ Greet identity
4139

4240
farewell :: Initial Unit
4341
farewell = liftF $ Farewell unit
@@ -46,10 +44,10 @@ farewell = liftF $ Farewell unit
4644
-- | us to map one action in `InitialF` to multiple actions in `TeletypeF` (see
4745
-- | the `Greet` case - we're expanding one `InitialF` action into 3 `TeletypeF`
4846
-- | actions).
49-
runInitial :: NaturalTransformation Initial Teletype
47+
runInitial :: Initial ~> Teletype
5048
runInitial initial = foldFree go initial
5149
where
52-
go :: NaturalTransformation InitialF Teletype
50+
go :: InitialF ~> Teletype
5351
go (Greet k) = do
5452
name <- getLine
5553
putStrLn $ "Hello " <> name
@@ -65,7 +63,7 @@ test = do
6563
pure name
6664

6765
-- Run the thing
68-
main :: forall eff. Eff (console :: CONSOLE | eff) Unit
66+
main :: Effect Unit
6967
main = do
7068
a <- runTeletype (runInitial test)
7169
log $ "Input name while running: " <> a

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ module Test.Control.Monad.Free.Teletype where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, log)
5+
import Effect (Effect)
6+
import Effect.Console (log)
77
import Control.Monad.Free (Free, foldFree, liftF)
88

9-
import Data.NaturalTransformation (NaturalTransformation)
10-
119
data TeletypeF a = PutStrLn String a | GetLine (String -> a)
1210

1311
type Teletype a = Free TeletypeF a
@@ -16,13 +14,13 @@ putStrLn :: String -> Teletype Unit
1614
putStrLn s = liftF (PutStrLn s unit)
1715

1816
getLine :: Teletype String
19-
getLine = liftF (GetLine id)
17+
getLine = liftF (GetLine identity)
2018

21-
teletypeN :: forall eff. NaturalTransformation TeletypeF (Eff (console :: CONSOLE | eff))
19+
teletypeN :: TeletypeF ~> Effect
2220
teletypeN (PutStrLn s a) = const a <$> log s
2321
teletypeN (GetLine k) = pure (k "fake input")
2422

25-
run :: forall eff. NaturalTransformation Teletype (Eff (console :: CONSOLE | eff))
23+
run :: Teletype ~> Effect
2624
run = foldFree teletypeN
2725

2826
echo :: Teletype String
@@ -32,7 +30,7 @@ echo = do
3230
putStrLn "Finished"
3331
pure $ a <> a
3432

35-
main :: forall eff. Eff (console :: CONSOLE | eff) Unit
33+
main :: Effect Unit
3634
main = do
3735
a <- run $ echo
3836
log a

test/Test/Main.purs

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

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, log)
7-
5+
import Effect (Effect)
6+
import Effect.Console (log)
87
import Test.Control.Monad.Free.Coproduct as C
98
import Test.Control.Monad.Free.Stratified as S
109
import Test.Control.Monad.Free.Teletype as T
1110

12-
main :: Eff (console :: CONSOLE) Unit
11+
main :: Effect Unit
1312
main = do
1413
log "Teletype"
1514
T.main

0 commit comments

Comments
 (0)