Skip to content

Commit c014b68

Browse files
natefaubionLiamGoodacre
authored andcommitted
Migrate Eff to Effect
1 parent 740d3f9 commit c014b68

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-eff": "^3.0.0",
2120
"purescript-either": "^3.0.0",
22-
"purescript-maybe": "^3.0.0"
21+
"purescript-maybe": "^3.0.0",
22+
"purescript-effect": "^0.1.0"
2323
}
2424
}

src/Control/Monad/Eff/Exception.purs renamed to src/Control/Monad/Effect/Exception.purs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
-- | This module defines an effect, actions and handlers for working
22
-- | with JavaScript exceptions.
33

4-
module Control.Monad.Eff.Exception
5-
( EXCEPTION
6-
, Error
4+
module Control.Monad.Effect.Exception
5+
( Error
76
, error
87
, message
98
, name
@@ -16,14 +15,11 @@ module Control.Monad.Eff.Exception
1615

1716
import Prelude
1817

19-
import Control.Monad.Eff (Eff, kind Effect)
18+
import Control.Monad.Effect (Effect)
2019

2120
import Data.Either (Either(..))
2221
import Data.Maybe (Maybe(..))
2322

24-
-- | This effect is used to annotate code which possibly throws exceptions
25-
foreign import data EXCEPTION :: Effect
26-
2723
-- | The type of JavaScript errors
2824
foreign import data Error :: Type
2925

@@ -62,29 +58,27 @@ foreign import stackImpl
6258
-- | error "Expected a non-negative number"
6359
-- | ```
6460
foreign import throwException
65-
:: forall a eff
61+
:: forall a
6662
. Error
67-
-> Eff (exception :: EXCEPTION | eff) a
63+
-> Effect a
6864

6965
-- | Catch an exception by providing an exception handler.
7066
-- |
71-
-- | This handler removes the `EXCEPTION` effect.
72-
-- |
7367
-- | For example:
7468
-- |
7569
-- | ```purescript
7670
-- | main = catchException print do
7771
-- | Console.log "Exceptions thrown in this block will be logged to the console"
7872
-- | ```
7973
foreign import catchException
80-
:: forall a eff
81-
. (Error -> Eff eff a)
82-
-> Eff (exception :: EXCEPTION | eff) a
83-
-> Eff eff a
74+
:: forall a
75+
. (Error -> Effect a)
76+
-> Effect a
77+
-> Effect a
8478

8579
-- | A shortcut allowing you to throw an error in one step. Defined as
8680
-- | `throwException <<< error`.
87-
throw :: forall eff a. String -> Eff (exception :: EXCEPTION | eff) a
81+
throw :: forall a. String -> Effect a
8882
throw = throwException <<< error
8983

9084
-- | Runs an Eff and returns eventual Exceptions as a `Left` value. If the
@@ -93,8 +87,7 @@ throw = throwException <<< error
9387
-- | For example:
9488
-- |
9589
-- | ```purescript
96-
-- | -- Notice that there is no EXCEPTION effect
97-
-- | main :: forall eff. Eff (console :: CONSOLE, fs :: FS | eff) Unit
90+
-- | main :: forall eff. Effect Unit
9891
-- | main = do
9992
-- | result <- try (readTextFile UTF8 "README.md")
10093
-- | case result of
@@ -104,5 +97,5 @@ throw = throwException <<< error
10497
-- | Console.error ("Couldn't open README.md. Error was: " <> show error)
10598
-- | ```
10699

107-
try :: forall eff a. Eff (exception :: EXCEPTION | eff) a -> Eff eff (Either Error a)
100+
try :: forall a. Effect a -> Effect (Either Error a)
108101
try action = catchException (pure <<< Left) (Right <$> action)

src/Control/Monad/Eff/Exception/Unsafe.purs renamed to src/Control/Monad/Effect/Exception/Unsafe.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
module Control.Monad.Eff.Exception.Unsafe where
1+
module Control.Monad.Effect.Exception.Unsafe where
22

3-
import Control.Monad.Eff.Exception (Error, error, throwException)
4-
import Control.Monad.Eff.Unsafe (unsafePerformEff)
3+
import Control.Monad.Effect.Exception (Error, error, throwException)
4+
import Control.Monad.Effect.Unsafe (unsafePerformEffect)
55
import Control.Semigroupoid ((<<<))
66

77
-- | Throw an exception in pure code. This function should be used very
88
-- | sparingly, as it can cause unexpected crashes at runtime.
99
unsafeThrowException :: forall a. Error -> a
10-
unsafeThrowException = unsafePerformEff <<< throwException
10+
unsafeThrowException = unsafePerformEffect <<< throwException
1111

1212
-- | Defined as `unsafeThrowException <<< error`.
1313
unsafeThrow :: forall a. String -> a

0 commit comments

Comments
 (0)