From 6da848dfc834ff551dca3bbbec59f7f0ee0ebf94 Mon Sep 17 00:00:00 2001 From: Nathan Faubion Date: Tue, 28 Mar 2017 12:20:01 -0500 Subject: [PATCH] Updates for 0.11 --- bower.json | 14 +++++++------- package.json | 4 ++-- src/Control/Monad/Aff.purs | 21 ++++++++++++--------- src/Control/Monad/Aff/AVar.purs | 3 ++- src/Control/Monad/Aff/Internal.purs | 4 ++-- test/Test/Main.purs | 14 +++++++------- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/bower.json b/bower.json index 3fe49c2..812c448 100644 --- a/bower.json +++ b/bower.json @@ -17,14 +17,14 @@ "package.json" ], "dependencies": { - "purescript-console": "^2.0.0", - "purescript-exceptions": "^2.0.0", - "purescript-functions": "^2.0.0", - "purescript-parallel": "^2.0.0", - "purescript-transformers": "^2.0.1", - "purescript-unsafe-coerce": "^2.0.0" + "purescript-console": "^3.0.0", + "purescript-exceptions": "^3.0.0", + "purescript-functions": "^3.0.0", + "purescript-parallel": "^3.0.0", + "purescript-transformers": "^3.0.0", + "purescript-unsafe-coerce": "^3.0.0" }, "devDependencies": { - "purescript-partial": "^1.1.2" + "purescript-partial": "^1.2.0" } } diff --git a/package.json b/package.json index c711c63..cb29f2f 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "jscs": "^3.0.7", "jshint": "^2.9.4", "pulp": "^10.0.0", - "purescript-psa": "^0.4.0", - "purescript": "^0.10.1", + "purescript-psa": "^0.5.0-rc.1", + "purescript": "^0.11.0", "rimraf": "^2.5.4" } } diff --git a/src/Control/Monad/Aff.purs b/src/Control/Monad/Aff.purs index 52a1041..85a2402 100644 --- a/src/Control/Monad/Aff.purs +++ b/src/Control/Monad/Aff.purs @@ -25,10 +25,10 @@ import Prelude import Control.Alt (class Alt) import Control.Alternative (class Alternative) import Control.Monad.Aff.Internal (AVBox, AVar, _killVar, _putVar, _takeVar, _makeVar) -import Control.Monad.Eff (Eff) +import Control.Monad.Eff (Eff, kind Effect) import Control.Monad.Eff.Class (class MonadEff) import Control.Monad.Eff.Exception (Error, EXCEPTION, throwException, error) -import Control.Monad.Error.Class (class MonadError, throwError) +import Control.Monad.Error.Class (class MonadThrow, class MonadError, throwError) import Control.Monad.Rec.Class (class MonadRec, Step(..)) import Control.MonadPlus (class MonadZero, class MonadPlus) import Control.Parallel (class Parallel) @@ -47,7 +47,7 @@ import Unsafe.Coerce (unsafeCoerce) -- | errors or produces a value of type `a`. -- | -- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`. -foreign import data Aff :: # ! -> * -> * +foreign import data Aff :: # Effect -> Type -> Type -- | A pure asynchronous computation, having no effects other than -- | asynchronous computation. @@ -80,12 +80,12 @@ cancelWith aff c = runFn3 _cancelWith nonCanceler aff c -- | If you do need to handle exceptions, you can use `runAff` instead, or -- | you can handle the exception within the Aff computation, using -- | `catchError` (or any of the other mechanisms). -launchAff :: forall e a. Aff e a -> Eff (err :: EXCEPTION | e) (Canceler e) +launchAff :: forall e a. Aff e a -> Eff (exception :: EXCEPTION | e) (Canceler e) launchAff = lowerEx <<< runAff throwException (const (pure unit)) <<< liftEx where - liftEx :: Aff e a -> Aff (err :: EXCEPTION | e) a + liftEx :: Aff e a -> Aff (exception :: EXCEPTION | e) a liftEx = _unsafeInterleaveAff - lowerEx :: Eff (err :: EXCEPTION | e) (Canceler (err :: EXCEPTION | e)) -> Eff (err :: EXCEPTION | e) (Canceler e) + lowerEx :: Eff (exception :: EXCEPTION | e) (Canceler (exception :: EXCEPTION | e)) -> Eff (exception :: EXCEPTION | e) (Canceler e) lowerEx = map (Canceler <<< map _unsafeInterleaveAff <<< cancel) -- | Runs the asynchronous computation. You must supply an error callback and a @@ -149,7 +149,7 @@ apathize :: forall e a. Aff e a -> Aff e Unit apathize a = const unit <$> attempt a -- | Lifts a synchronous computation and makes explicit any failure from exceptions. -liftEff' :: forall e a. Eff (err :: EXCEPTION | e) a -> Aff e (Either Error a) +liftEff' :: forall e a. Eff (exception :: EXCEPTION | e) a -> Aff e (Either Error a) liftEff' eff = attempt (_unsafeInterleaveAff (runFn2 _liftEff nonCanceler eff)) -- | A constant canceller that always returns false. @@ -183,11 +183,14 @@ instance monadAff :: Monad (Aff e) instance monadEffAff :: MonadEff e (Aff e) where liftEff eff = runFn2 _liftEff nonCanceler eff --- | Allows users to catch and throw errors on the error channel of the +-- | Allows users to throw errors on the error channel of the -- | asynchronous computation. See documentation in `purescript-transformers`. -instance monadErrorAff :: MonadError Error (Aff e) where +instance monadThrowAff :: MonadThrow Error (Aff e) where throwError e = runFn2 _throwError nonCanceler e +-- | Allows users to catch errors on the error channel of the +-- | asynchronous computation. See documentation in `purescript-transformers`. +instance monadErrorAff :: MonadError Error (Aff e) where catchError aff ex = attempt aff >>= either ex pure instance altAff :: Alt (Aff e) where diff --git a/src/Control/Monad/Aff/AVar.purs b/src/Control/Monad/Aff/AVar.purs index 8b6970e..3e05f7a 100644 --- a/src/Control/Monad/Aff/AVar.purs +++ b/src/Control/Monad/Aff/AVar.purs @@ -17,13 +17,14 @@ import Prelude import Control.Monad.Aff (Aff, nonCanceler) import Control.Monad.Aff.Internal (AVar) as Exports import Control.Monad.Aff.Internal (AVBox, AVar, _killVar, _putVar, _takeVar, _peekVar, _makeVar) +import Control.Monad.Eff (kind Effect) import Control.Monad.Eff.Exception (Error()) import Data.Function.Uncurried (runFn3, runFn2) import Unsafe.Coerce (unsafeCoerce) -foreign import data AVAR :: ! +foreign import data AVAR :: Effect type AffAVar e a = Aff (avar :: AVAR | e) a diff --git a/src/Control/Monad/Aff/Internal.purs b/src/Control/Monad/Aff/Internal.purs index 5f4e0fc..52f95cf 100644 --- a/src/Control/Monad/Aff/Internal.purs +++ b/src/Control/Monad/Aff/Internal.purs @@ -14,9 +14,9 @@ import Control.Monad.Eff.Exception (Error) import Data.Function.Uncurried (Fn2, Fn3) -foreign import data AVar :: * -> * +foreign import data AVar :: Type -> Type -foreign import data AVBox :: * -> * +foreign import data AVBox :: Type -> Type foreign import _makeVar :: forall c a. c -> AVBox (AVar a) diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 3f86d87..8924131 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -75,7 +75,7 @@ test_apathize = do test_putTakeVar :: TestAVar Unit test_putTakeVar = do v <- makeVar - forkAff (later $ putVar v 1.0) + _ <- forkAff (later $ putVar v 1.0) a <- takeVar v log ("Success: Value " <> show a) @@ -83,7 +83,7 @@ test_peekVar :: TestAVar Unit test_peekVar = do timeout 1000 do v <- makeVar - forkAff (later $ putVar v 1.0) + _ <- forkAff (later $ putVar v 1.0) a1 <- peekVar v a2 <- takeVar v when (a1 /= a2) do @@ -101,7 +101,7 @@ test_peekVar = do timeout 1000 do x <- makeVar res <- makeVar' 1 - forkAff do + _ <- forkAff do c <- peekVar x putVar x 1000 d <- peekVar x @@ -176,13 +176,13 @@ test_semigroupCanceler = test_cancelLater :: TestAVar Unit test_cancelLater = do - c <- forkAff $ (do pure "Binding" + c <- forkAff $ (do _ <- pure "Binding" _ <- later' 100 $ log ("Failure: Later was not canceled!") pure "Binding") v <- cancel c (error "Cause") log (if v then "Success: Canceled later" else "Failure: Did not cancel later") -test_cancelLaunchLater :: forall e. Eff (console :: CONSOLE, err :: EXCEPTION | e) Unit +test_cancelLaunchLater :: forall e. Eff (console :: CONSOLE, exception :: EXCEPTION | e) Unit test_cancelLaunchLater = do c <- launchAff $ later' 100 $ log ("Failure: Later was not canceled!") void $ launchAff $ (do v <- cancel c (error "Cause") @@ -249,7 +249,7 @@ loopAndBounce n = do all :: forall eff. Int -> Aff (console :: CONSOLE, avar :: AVAR | eff) Unit all n = do var <- makeVar' 0 - forkAll $ replicateArray n (modifyVar (_ + 1) var) + _ <- forkAll $ replicateArray n (modifyVar (_ + 1) var) count <- takeVar var log ("Forked " <> show count) @@ -262,7 +262,7 @@ cancelAll n = do delay :: forall eff. Int -> Aff eff Unit delay n = later' n (pure unit) -main :: Eff (console :: CONSOLE, avar :: AVAR, err :: EXCEPTION) Unit +main :: Eff (console :: CONSOLE, avar :: AVAR, exception :: EXCEPTION) Unit main = do Eff.log "Testing kill of later launched in separate Aff" test_cancelLaunchLater