Skip to content

Commit 4d6c8b0

Browse files
authored
Merge pull request #25 from purescript/compiler/0.12
Updates for 0.12
2 parents 188eab3 + 2417fdf commit 4d6c8b0

File tree

7 files changed

+72
-81
lines changed

7 files changed

+72
-81
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/bower_components/
55
/node_modules/
66
/output/
7+
package-lock.json

LICENSE

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

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

12-
The above copyright notice and this permission notice shall be
13-
included 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.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22-
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: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "purescript-parallel",
3-
"description": "Type classes for parallel computation",
4-
"license": "MIT",
3+
"license": "BSD-3-Clause",
54
"repository": {
65
"type": "git",
76
"url": "git://github.com/purescript/purescript-parallel.git"
@@ -16,13 +15,19 @@
1615
"package.json"
1716
],
1817
"dependencies": {
19-
"purescript-transformers": "^3.0.0",
20-
"purescript-refs": "^3.0.0",
21-
"purescript-functors": "^2.0.0",
22-
"purescript-foldable-traversable": "^3.6.0"
18+
"purescript-control": "^4.0.0",
19+
"purescript-effect": "^2.0.0",
20+
"purescript-either": "^4.0.0",
21+
"purescript-foldable-traversable": "^4.0.0",
22+
"purescript-functors": "^3.0.0",
23+
"purescript-maybe": "^4.0.0",
24+
"purescript-newtype": "^3.0.0",
25+
"purescript-prelude": "^4.0.0",
26+
"purescript-refs": "^4.0.0",
27+
"purescript-transformers": "^4.0.0"
2328
},
2429
"devDependencies": {
25-
"purescript-console": "^3.0.0",
26-
"purescript-functions": "^3.0.0"
30+
"purescript-console": "^4.0.0",
31+
"purescript-functions": "^4.0.0"
2732
}
2833
}

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.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
1212
}
1313
}

src/Control/Parallel.purs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module Control.Parallel
2-
( parTraverse
2+
( parApply
3+
, parTraverse
34
, parTraverse_
45
, parSequence
56
, parSequence_
67
, parOneOf
78
, parOneOfMap
8-
, parApply
99
, module Control.Parallel.Class
1010
) where
1111

@@ -26,7 +26,6 @@ parApply
2626
-> m b
2727
parApply mf ma = sequential(apply (parallel mf) (parallel ma))
2828

29-
3029
-- | Traverse a collection in parallel.
3130
parTraverse
3231
:: forall f m t a b
@@ -53,15 +52,15 @@ parSequence
5352
=> Traversable t
5453
=> t (m a)
5554
-> m (t a)
56-
parSequence = parTraverse id
55+
parSequence = parTraverse identity
5756

5857
parSequence_
5958
:: forall a t m f
6059
. Parallel f m
6160
=> Foldable t
6261
=> t (m a)
6362
-> m Unit
64-
parSequence_ = parTraverse_ id
63+
parSequence_ = parTraverse_ identity
6564

6665
-- | Race a collection in parallel.
6766
parOneOf

src/Control/Parallel/Class.purs

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
1-
module Control.Parallel.Class
2-
( class Parallel
3-
, parallel
4-
, sequential
5-
, ParCont(..)
6-
) where
1+
module Control.Parallel.Class where
72

83
import Prelude
94

105
import Control.Alt (class Alt)
116
import Control.Alternative (class Alternative)
127
import Control.Monad.Cont.Trans (ContT(..), runContT)
13-
import Control.Monad.Eff (Eff)
14-
import Control.Monad.Eff.Class (class MonadEff, liftEff)
15-
import Control.Monad.Eff.Ref (REF, writeRef, readRef, newRef)
16-
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)
178
import Control.Monad.Except.Trans (ExceptT(..))
189
import Control.Monad.Maybe.Trans (MaybeT(..))
1910
import Control.Monad.Reader.Trans (mapReaderT, ReaderT)
2011
import Control.Monad.Writer.Trans (mapWriterT, WriterT)
2112
import Control.Plus (class Plus)
22-
2313
import Data.Either (Either)
2414
import Data.Functor.Compose (Compose(..))
2515
import Data.Maybe (Maybe(..))
26-
import Data.Monoid (class Monoid)
2716
import Data.Newtype (class Newtype)
17+
import Effect.Class (class MonadEffect, liftEffect)
18+
import Effect.Ref as Ref
2819

2920
-- | The `Parallel` class abstracts over monads which support
3021
-- | parallel composition via some related `Applicative`.
3122
class (Monad m, Applicative f) <= Parallel f m | m -> f, f -> m where
32-
parallel :: m ~> f
23+
parallel :: m ~> f
3324
sequential :: f ~> m
3425

3526
instance monadParExceptT :: Parallel f m => Parallel (Compose f (Either e)) (ExceptT e m) where
@@ -67,57 +58,54 @@ newtype ParCont m a = ParCont (ContT Unit m a)
6758

6859
derive instance newtypeParCont :: Newtype (ParCont m a) _
6960

70-
instance functorParCont :: MonadEff eff m => Functor (ParCont m) where
61+
instance functorParCont :: MonadEffect m => Functor (ParCont m) where
7162
map f = parallel <<< map f <<< sequential
7263

73-
instance applyParCont :: MonadEff eff m => Apply (ParCont m) where
64+
instance applyParCont :: MonadEffect m => Apply (ParCont m) where
7465
apply (ParCont ca) (ParCont cb) = ParCont $ ContT \k -> do
75-
ra <- liftEff $ unsafeWithRef (newRef Nothing)
76-
rb <- liftEff $ unsafeWithRef (newRef Nothing)
66+
ra <- liftEffect (Ref.new Nothing)
67+
rb <- liftEffect (Ref.new Nothing)
7768

7869
runContT ca \a -> do
79-
mb <- liftEff $ unsafeWithRef (readRef rb)
70+
mb <- liftEffect (Ref.read rb)
8071
case mb of
81-
Nothing -> liftEff $ unsafeWithRef (writeRef ra (Just a))
72+
Nothing -> liftEffect (Ref.write (Just a) ra)
8273
Just b -> k (a b)
8374

8475
runContT cb \b -> do
85-
ma <- liftEff $ unsafeWithRef (readRef ra)
76+
ma <- liftEffect (Ref.read ra)
8677
case ma of
87-
Nothing -> liftEff $ unsafeWithRef (writeRef rb (Just b))
78+
Nothing -> liftEffect (Ref.write (Just b) rb)
8879
Just a -> k (a b)
8980

90-
instance applicativeParCont :: MonadEff eff m => Applicative (ParCont m) where
81+
instance applicativeParCont :: MonadEffect m => Applicative (ParCont m) where
9182
pure = parallel <<< pure
9283

93-
instance altParCont :: MonadEff eff m => Alt (ParCont m) where
84+
instance altParCont :: MonadEffect m => Alt (ParCont m) where
9485
alt (ParCont c1) (ParCont c2) = ParCont $ ContT \k -> do
95-
done <- liftEff $ unsafeWithRef (newRef false)
86+
done <- liftEffect (Ref.new false)
9687

9788
runContT c1 \a -> do
98-
b <- liftEff $ unsafeWithRef (readRef done)
89+
b <- liftEffect (Ref.read done)
9990
if b
10091
then pure unit
10192
else do
102-
liftEff $ unsafeWithRef (writeRef done true)
93+
liftEffect (Ref.write true done)
10394
k a
10495

10596
runContT c2 \a -> do
106-
b <- liftEff $ unsafeWithRef (readRef done)
97+
b <- liftEffect (Ref.read done)
10798
if b
10899
then pure unit
109100
else do
110-
liftEff $ unsafeWithRef (writeRef done true)
101+
liftEffect (Ref.write true done)
111102
k a
112103

113-
instance plusParCont :: MonadEff eff m => Plus (ParCont m) where
104+
instance plusParCont :: MonadEffect m => Plus (ParCont m) where
114105
empty = ParCont $ ContT \_ -> pure unit
115106

116-
instance alternativeParCont :: MonadEff eff m => Alternative (ParCont m)
107+
instance alternativeParCont :: MonadEffect m => Alternative (ParCont m)
117108

118-
instance monadParParCont :: MonadEff eff m => Parallel (ParCont m) (ContT Unit m) where
109+
instance monadParParCont :: MonadEffect m => Parallel (ParCont m) (ContT Unit m) where
119110
parallel = ParCont
120111
sequential (ParCont ma) = ma
121-
122-
unsafeWithRef :: forall eff a. Eff (ref :: REF | eff) a -> Eff eff a
123-
unsafeWithRef = unsafeCoerceEff

test/Main.purs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
module Test.Main where
22

3-
import Prelude (Unit, (<<<))
3+
import Prelude
44

55
import Control.Monad.Cont.Trans (ContT(..), runContT)
6-
import Control.Monad.Eff (Eff, kind Effect)
7-
import Control.Monad.Eff.Console (CONSOLE, logShow)
86
import Control.Parallel (parTraverse)
7+
import Effect (Effect)
8+
import Effect.Console (logShow)
99

1010
newtype Request = Request
1111
{ host :: String
1212
, path :: String
1313
}
1414

15-
foreign import data HTTP :: Effect
15+
foreign import getImpl :: Request -> (String -> Effect Unit) -> Effect Unit
1616

17-
foreign import getImpl
18-
:: forall eff
19-
. Request
20-
-> (String -> Eff (http :: HTTP | eff) Unit)
21-
-> Eff (http :: HTTP | eff) Unit
22-
23-
get :: forall eff. Request -> ContT Unit (Eff (http :: HTTP | eff)) String
17+
get :: Request -> ContT Unit Effect String
2418
get req = ContT (getImpl req)
2519

2620
request :: String -> Request
2721
request host = Request { host: host, path: "/" }
2822

29-
main :: forall eff. Eff (http :: HTTP, console :: CONSOLE | eff) Unit
23+
main :: Effect Unit
3024
main = runContT (parTraverse (get <<< request) resources) logShow
3125
where
3226
resources :: Array String

0 commit comments

Comments
 (0)