Skip to content

Commit b5eadd2

Browse files
committed
Updates for 0.7
1 parent 0737506 commit b5eadd2

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

src/Control/Monad/Eff/Exception.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Control.Monad.Eff.Exception
5+
6+
exports.showErrorImpl = function(err) {
7+
return err.stack || err.toString();
8+
};
9+
10+
exports.error = function(msg) {
11+
return new Error(msg);
12+
};
13+
14+
exports.message = function(e) {
15+
return e.message;
16+
};
17+
18+
exports.throwException = function(e) {
19+
return function() {
20+
throw e;
21+
};
22+
};
23+
24+
exports.catchException = function(c) {
25+
return function(t) {
26+
return function() {
27+
try {
28+
return t();
29+
} catch(e) {
30+
if (e instanceof Error || Object.prototype.toString.call(e) === '[object Error]') {
31+
return c(e)();
32+
} else {
33+
return c(new Error(e.toString()))();
34+
}
35+
}
36+
};
37+
};
38+
};

src/Control/Monad/Eff/Exception.purs

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Control.Monad.Eff.Exception
1010
, catchException
1111
) where
1212

13+
import Prelude
1314
import Control.Monad.Eff (Eff())
1415

1516
-- | This effect is used to annotate code which possibly throws exceptions
@@ -21,28 +22,13 @@ foreign import data Error :: *
2122
instance showError :: Show Error where
2223
show = showErrorImpl
2324

24-
foreign import showErrorImpl
25-
"""
26-
function showErrorImpl(err) {
27-
return err.stack || err.toString();
28-
}
29-
""" :: Error -> String
25+
foreign import showErrorImpl :: Error -> String
3026

3127
-- | Create a Javascript error, specifying a message
32-
foreign import error
33-
"""
34-
function error(msg) {
35-
return new Error(msg);
36-
}
37-
""" :: String -> Error
28+
foreign import error :: String -> Error
3829

3930
-- | Get the error message from a Javascript error
40-
foreign import message
41-
"""
42-
function message(e) {
43-
return e.message;
44-
}
45-
""" :: Error -> String
31+
foreign import message :: Error -> String
4632

4733
-- | Throw an exception
4834
-- |
@@ -54,14 +40,7 @@ foreign import message
5440
-- | when (x < 0) $ throwException $
5541
-- | error "Expected a non-negative number"
5642
-- | ```
57-
foreign import throwException
58-
"""
59-
function throwException(e) {
60-
return function() {
61-
throw e;
62-
};
63-
}
64-
""" :: forall a eff. Error -> Eff (err :: EXCEPTION | eff) a
43+
foreign import throwException :: forall a eff. Error -> Eff (err :: EXCEPTION | eff) a
6544

6645
-- | Catch an exception by providing an exception handler.
6746
-- |
@@ -73,21 +52,4 @@ foreign import throwException
7352
-- | main = catchException print do
7453
-- | trace "Exceptions thrown in this block will be logged to the console"
7554
-- | ```
76-
foreign import catchException
77-
"""
78-
function catchException(c) {
79-
return function(t) {
80-
return function() {
81-
try {
82-
return t();
83-
} catch(e) {
84-
if (e instanceof Error || Object.prototype.toString.call(e) === '[object Error]') {
85-
return c(e)();
86-
} else {
87-
return c(new Error(e.toString()))();
88-
}
89-
}
90-
};
91-
};
92-
}
93-
""" :: forall a eff. (Error -> Eff eff a) -> Eff (err :: EXCEPTION | eff) a -> Eff eff a
55+
foreign import catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: EXCEPTION | eff) a -> Eff eff a

0 commit comments

Comments
 (0)