Skip to content

Commit 4531d84

Browse files
authored
Merge pull request #21 from garyb/compiler/0.12
Compiler/0.12
2 parents ed00bf3 + 99f114b commit 4531d84

File tree

6 files changed

+70
-84
lines changed

6 files changed

+70
-84
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ language: node_js
22
dist: trusty
33
sudo: required
44
node_js: stable
5+
env:
6+
- PATH=$HOME/purescript:$PATH
57
install:
8+
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
9+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
10+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
11+
- chmod a+x $HOME/purescript
612
- npm install -g bower
713
- npm install
814
- bower install

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-prelude": "^3.0.0"
19+
"purescript-prelude": "^4.0.0"
2020
},
2121
"devDependencies": {
22-
"purescript-eff": "^3.1.0"
22+
"purescript-effect": "^2.0.0"
2323
}
2424
}

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
"build": "eslint src && pulp build -- --censor-lib --strict"
66
},
77
"devDependencies": {
8-
"eslint": "^3.19.0",
9-
"pulp": "^11.0.0",
10-
"purescript": "^0.11.1",
11-
"purescript-psa": "^0.5.0",
12-
"rimraf": "^2.6.1"
8+
"eslint": "^4.19.1",
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
1312
}
1413
}

src/Debug/Trace.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var req = typeof module === "undefined" ? undefined : module.require;
55
var util = req === undefined ? undefined : req("util");
66

7-
exports.traceAny = function () {
7+
exports.trace = function () {
88
return function (x) {
99
return function (k) {
1010
// node only recurses two levels into an object before printing
@@ -18,3 +18,16 @@ exports.traceAny = function () {
1818
};
1919
};
2020
};
21+
22+
exports.spy = function () {
23+
return function (tag) {
24+
return function (x) {
25+
if (util !== undefined) {
26+
console.log(tag + ":", util.inspect(x, { depth: null, colors: true }));
27+
} else {
28+
console.log(tag + ":", x);
29+
}
30+
return x;
31+
};
32+
};
33+
};

src/Debug/Trace.purs

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,35 @@ module Debug.Trace where
22

33
import Prelude
44

5+
import Prim.TypeError (class Warn, Text)
6+
57
-- | Nullary class used to raise a custom warning for the debug functions.
68
class DebugWarning
79

8-
instance warn :: Warn "Debug.Trace usage" => DebugWarning
10+
instance warn :: Warn (Text "Debug.Trace usage") => DebugWarning
911

10-
-- | Log a message to the console for debugging purposes and then return a
11-
-- | value. The return value is thunked so it is not evaluated until after the
12+
-- | Log any PureScript value to the console for debugging purposes and then
13+
-- | return a value. This will log the value's underlying representation for
14+
-- | low-level debugging, so it may be desireable to `show` the value first.
15+
-- |
16+
-- | The return value is thunked so it is not evaluated until after the
1217
-- | message has been printed, to preserve a predictable console output.
1318
-- |
1419
-- | For example:
1520
-- | ``` purescript
1621
-- | doSomething = trace "Hello" \_ -> ... some value or computation ...
1722
-- | ```
18-
trace :: forall a. DebugWarning => String -> (Unit -> a) -> a
19-
trace = traceAny
20-
21-
-- | Log a `Show`able value to the console for debugging purposes and then
22-
-- | return a value.
23-
traceShow :: forall a b. DebugWarning => Show a => a -> (Unit -> b) -> b
24-
traceShow = traceAny <<< show
25-
26-
-- | Log any PureScript value to the console for debugging purposes and then
27-
-- | return a value. This will log the value's underlying representation for
28-
-- | low-level debugging.
29-
foreign import traceAny :: forall a b. DebugWarning => a -> (Unit -> b) -> b
30-
31-
-- | Log any value and return it
32-
spy :: forall a. DebugWarning => a -> a
33-
spy a = traceAny a \_ -> a
23+
foreign import trace :: forall a b. DebugWarning => a -> (Unit -> b) -> b
3424

3525
-- | Log any PureScript value to the console and return the unit value of the
36-
-- | Applicative `a`.
37-
traceAnyA :: forall a b. DebugWarning => Applicative a => b -> a Unit
38-
traceAnyA s = traceAny s \_ -> pure unit
39-
40-
-- | Log a message to the console for debugging purposes and then return the
41-
-- | unit value of the Applicative `a`.
42-
-- |
43-
-- | For example:
44-
-- | ``` purescript
45-
-- | doSomething = do
46-
-- | traceA "Hello"
47-
-- | ... some value or computation ...
48-
-- | ```
49-
traceA :: forall a. DebugWarning => Applicative a => String -> a Unit
50-
traceA = traceAnyA
51-
52-
-- | Log a `Show`able value to the console for debugging purposes and then
53-
-- | return the unit value of the Applicative `a`.
54-
traceShowA :: forall a b. DebugWarning => Show b => Applicative a => b -> a Unit
55-
traceShowA = traceAnyA <<< show
56-
57-
-- | Log any PureScript value to the console and return it in `Monad`
58-
-- | useful when one has monadic chains
59-
-- | ```purescript
60-
-- | mbArray :: Maybe (Array Int)
61-
-- | foo :: Int
62-
-- | foo = fromMaybe zero
63-
-- | $ mbArray
64-
-- | >>= traceAnyM
65-
-- | >>= head
66-
-- | >>= traceAnyM
67-
-- | ```
68-
traceAnyM :: forall m a. DebugWarning => Monad m => a -> m a
69-
traceAnyM s = traceAny s \_ -> pure s
70-
71-
-- | Same as `traceAnyM` but only for `Show`able values
72-
traceShowM :: forall m a. DebugWarning => Show a => Monad m => a -> m a
73-
traceShowM s = traceAny (show s) \_ -> pure s
26+
-- | Monad `m`.
27+
traceM :: forall m a. DebugWarning => Monad m => a -> m Unit
28+
traceM s = do
29+
pure unit
30+
trace s \_ -> pure unit
31+
32+
-- | Logs any value and returns it, using a "tag" or key value to annotate the
33+
-- | traced value. Useful when debugging something in the middle of a
34+
-- | expression, as you can insert this into the expression without having to
35+
-- | break it up.
36+
foreign import spy :: forall a. DebugWarning => String -> a -> a

test/Main.purs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
module Test.Main where
22

33
import Prelude
4-
import Debug.Trace (traceAnyA, spy, traceA, traceAnyM, traceAny, traceShow, trace)
5-
import Control.Monad.Eff (Eff)
4+
import Debug.Trace (spy, trace, traceM)
5+
import Effect (Effect)
66

7-
main :: Eff () Unit
7+
main :: Effect Unit
88
main = do
99
trace "Testing" \_ ->
10-
traceShow true \_ ->
11-
traceAny { x: 10 } \_ ->
12-
pure unit
13-
traceA "Testing"
14-
traceAnyA { x: 10 }
15-
16-
void $ traceAnyM "Testing"
17-
effInt >>= traceAnyM >>= eatInt
18-
effRec >>= traceAnyM >>= \r -> do
19-
traceA r.x
20-
21-
let dummy = spy { foo: 1, bar: [1, 2] }
22-
traceAnyA dummy
10+
trace true \_ ->
11+
trace { x: 10 } \_ -> do
12+
traceM "Testing"
13+
traceM { x: 10 }
14+
15+
traceM "Testing"
16+
17+
effInt
18+
>>= spy "i"
19+
>>> eatInt
20+
21+
effRec
22+
>>= spy "r"
23+
>>> \r -> traceM r.x
24+
25+
let dummy = spy "dummy" { foo: 1, bar: [1, 2] }
26+
traceM dummy
27+
2328
where
24-
effInt :: Eff () Int
29+
effInt :: Effect Int
2530
effInt = pure 0
2631

27-
effRec :: Eff () { x :: String }
32+
effRec :: Effect { x :: String }
2833
effRec = pure { x : "foo" }
2934

30-
eatInt :: Int -> Eff () Unit
35+
eatInt :: Int -> Effect Unit
3136
eatInt = const $ pure unit

0 commit comments

Comments
 (0)