Skip to content

Commit 3b8f3ae

Browse files
authored
Merge pull request #71 from purescript/compiler/0.12
Update for PureScript 0.12
2 parents 1de4a2e + fb51a84 commit 3b8f3ae

20 files changed

+114
-142
lines changed

.gitignore

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

LICENSE

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
The MIT License (MIT)
1+
Copyright 2018 PureScript
22

3-
Copyright (c) 2014 PureScript
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
45

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
the Software, and to permit persons to whom the Software is furnished to do so,
10-
subject to the following conditions:
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
118

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of 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.
1412

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "purescript-foreign",
33
"homepage": "https://github.com/purescript/purescript-foreign",
4-
"description": "PureScript library for dealing with foreign data (JSON and JavaScript objects)",
54
"authors": [
65
"Gary Burgess <[email protected]>",
76
"Phil Freeman <[email protected]>"
@@ -10,7 +9,7 @@
109
"type": "git",
1110
"url": "git://github.com/purescript/purescript-foreign.git"
1211
},
13-
"license": "MIT",
12+
"license": "BSD-3-Clause",
1413
"ignore": [
1514
"**/.*",
1615
"bower_components",
@@ -21,16 +20,17 @@
2120
"package.json"
2221
],
2322
"dependencies": {
24-
"purescript-arrays": "^4.0.0",
25-
"purescript-either": "^3.0.0",
26-
"purescript-foldable-traversable": "^3.0.0",
27-
"purescript-functions": "^3.0.0",
28-
"purescript-integers": "^3.0.0",
29-
"purescript-lists": "^4.0.0",
30-
"purescript-strings": "^3.0.0",
31-
"purescript-transformers": "^3.0.0"
23+
"purescript-either": "^4.0.0",
24+
"purescript-functions": "^4.0.0",
25+
"purescript-identity": "^4.0.0",
26+
"purescript-integers": "^4.0.0",
27+
"purescript-lists": "^5.0.0",
28+
"purescript-maybe": "^4.0.0",
29+
"purescript-prelude": "^4.0.0",
30+
"purescript-strings": "^4.0.0",
31+
"purescript-transformers": "^4.0.0"
3232
},
3333
"devDependencies": {
34-
"purescript-console": "^3.0.0"
34+
"purescript-console": "^4.0.0"
3535
}
3636
}

examples/Applicative.purs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ module Example.Applicative where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, logShow)
75
import Control.Monad.Except (runExcept)
8-
9-
import Data.Foreign (F, Foreign, readNumber)
10-
import Data.Foreign.Index ((!))
11-
6+
import Effect (Effect)
7+
import Effect.Console (logShow)
128
import Example.Util.Value (foreignValue)
9+
import Foreign (F, Foreign, readNumber)
10+
import Foreign.Index ((!))
1311

1412
data Point = Point Number Number Number
1513

@@ -23,7 +21,7 @@ readPoint value = do
2321
<*> (value ! "y" >>= readNumber)
2422
<*> (value ! "z" >>= readNumber)
2523

26-
main :: Eff (console :: CONSOLE) Unit
24+
main :: Effect Unit
2725
main =
2826
logShow $ runExcept $
2927
readPoint =<< foreignValue """{ "x": 1, "y": 2, "z": 3 }"""

examples/Arrays.purs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ module Example.Arrays where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, logShow)
75
import Control.Monad.Except (runExcept)
8-
9-
import Data.Foreign (readArray, readNumber, readString)
106
import Data.Traversable (traverse)
11-
7+
import Effect (Effect)
8+
import Effect.Console (logShow)
129
import Example.Util.Value (foreignValue)
10+
import Foreign (readArray, readNumber, readString)
1311

14-
main :: Eff (console :: CONSOLE) Unit
12+
main :: Effect Unit
1513
main = do
1614
logShow $ runExcept $
1715
traverse readString =<< readArray =<< foreignValue """["hello", "world"]"""

examples/Complex.purs

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,44 @@ module Example.Complex where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, logShow)
75
import Control.Monad.Except (runExcept)
8-
9-
import Data.Foreign (F, Foreign, readArray, readBoolean, readNumber, readString, readNullOrUndefined)
10-
import Data.Foreign.Index ((!))
11-
import Data.Traversable (traverse)
126
import Data.Maybe (Maybe)
13-
7+
import Data.Traversable (traverse)
8+
import Effect (Effect)
9+
import Effect.Console (logShow)
1410
import Example.Util.Value (foreignValue)
11+
import Foreign (F, Foreign, readArray, readBoolean, readNumber, readString, readNullOrUndefined)
12+
import Foreign.Index ((!))
1513

16-
newtype SomeObject =
17-
SomeObject
18-
{ foo :: String
19-
, bar :: Boolean
20-
, baz :: Number
21-
, list :: Array ListItem
22-
}
23-
24-
instance showSomeObject :: Show SomeObject where
25-
show (SomeObject o) =
26-
"(SomeObject { foo: " <> show o.foo <>
27-
", bar: " <> show o.bar <>
28-
", baz: " <> show o.baz <>
29-
", list: " <> show o.list <>
30-
"})"
14+
type SomeObject =
15+
{ foo :: String
16+
, bar :: Boolean
17+
, baz :: Number
18+
, list :: Array ListItem
19+
}
3120

3221
readSomeObject :: Foreign -> F SomeObject
3322
readSomeObject value = do
3423
foo <- value ! "foo" >>= readString
3524
bar <- value ! "bar" >>= readBoolean
3625
baz <- value ! "baz" >>= readNumber
3726
list <- value ! "list" >>= readArray >>= traverse readListItem
38-
pure $ SomeObject { foo, bar, baz, list }
39-
40-
newtype ListItem =
41-
ListItem
42-
{ x :: Number
43-
, y :: Number
44-
, z :: Maybe Number
45-
}
27+
pure { foo, bar, baz, list }
4628

47-
instance showListItem :: Show ListItem where
48-
show (ListItem o) =
49-
"(ListItem { x: " <> show o.x <>
50-
", y: " <> show o.y <>
51-
", z: " <> show o.z <>
52-
" })"
29+
type ListItem =
30+
{ x :: Number
31+
, y :: Number
32+
, z :: Maybe Number
33+
}
5334

5435
readListItem :: Foreign -> F ListItem
5536
readListItem value = do
5637
x <- value ! "x" >>= readNumber
5738
y <- value ! "y" >>= readNumber
5839
z <- value ! "z" >>= readNullOrUndefined >>= traverse readNumber
59-
pure $ ListItem { x, y, z }
40+
pure { x, y, z }
6041

61-
main :: Eff (console :: CONSOLE) Unit
42+
main :: Effect Unit
6243
main = do
6344
let json = """{"foo":"hello","bar":true,"baz":1,"list":[{"x":1,"y":2},{"x":3,"y":4,"z":999}]}"""
6445
logShow $ runExcept $ readSomeObject =<< foreignValue json

examples/MaybeNullable.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ module Example.MaybeNullable where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, logShow)
5+
import Effect (Effect)
6+
import Effect.Console (logShow)
77
import Control.Monad.Except (runExcept)
88

9-
import Data.Foreign (readBoolean, readNull)
9+
import Foreign (readBoolean, readNull)
1010
import Data.Traversable (traverse)
1111

1212
import Example.Util.Value (foreignValue)
1313

1414
-- Parsing values that are allowed to null or undefined is possible by
1515
-- using Maybe types.
16-
main :: Eff (console :: CONSOLE) Unit
16+
main :: Effect Unit
1717
main = do
1818
logShow $ runExcept $
1919
traverse readBoolean =<< readNull =<< foreignValue "null"

examples/Nested.purs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ module Example.Nested where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, logShow)
75
import Control.Monad.Except (runExcept)
8-
9-
import Data.Foreign (F, Foreign, readNumber, readString)
10-
import Data.Foreign.Index ((!))
11-
6+
import Effect (Effect)
7+
import Effect.Console (logShow)
128
import Example.Util.Value (foreignValue)
9+
import Foreign (F, Foreign, readNumber, readString)
10+
import Foreign.Index ((!))
1311

1412
data Foo = Foo Bar Baz
1513

@@ -32,7 +30,7 @@ readFoo value = do
3230
n <- value ! "foo" ! "baz" >>= readNumber
3331
pure $ Foo (Bar s) (Baz n)
3432

35-
main :: Eff (console :: CONSOLE) Unit
33+
main :: Effect Unit
3634
main =
3735
logShow $ runExcept $
3836
readFoo =<< foreignValue """{ "foo": { "bar": "bar", "baz": 1 } }"""

examples/Objects.purs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,22 @@ module Example.Objects where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, logShow)
75
import Control.Monad.Except (runExcept)
8-
9-
import Data.Foreign (F, Foreign, readNumber)
10-
import Data.Foreign.Index ((!))
11-
6+
import Effect (Effect)
7+
import Effect.Console (logShow)
128
import Example.Util.Value (foreignValue)
9+
import Foreign (F, Foreign, readNumber)
10+
import Foreign.Index ((!))
1311

14-
newtype Point = Point { x :: Number, y :: Number }
15-
16-
instance showPoint :: Show Point where
17-
show (Point { x, y }) =
18-
"(Point { x: " <> show x <> ", y: " <> show y <> " })"
12+
type Point = { x :: Number, y :: Number }
1913

2014
readPoint :: Foreign -> F Point
2115
readPoint value = do
2216
x <- value ! "x" >>= readNumber
2317
y <- value ! "y" >>= readNumber
24-
pure $ Point { x, y }
18+
pure { x, y }
2519

26-
main :: Eff (console :: CONSOLE) Unit
20+
main :: Effect Unit
2721
main = do
2822
logShow $ runExcept $
2923
readPoint =<< foreignValue """{ "x": 1, "y": 2 }"""

examples/ParseErrors.purs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ module Example.ParseErrors where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, logShow)
75
import Control.Monad.Except (runExcept)
8-
9-
import Data.Foreign (F, Foreign, readArray, readBoolean, readNumber, readString)
10-
import Data.Foreign.Index ((!))
116
import Data.Traversable (traverse)
12-
7+
import Effect (Effect)
8+
import Effect.Console (logShow)
139
import Example.Util.Value (foreignValue)
10+
import Foreign (F, Foreign, readArray, readBoolean, readNumber, readString)
11+
import Foreign.Index ((!))
1412

1513
newtype Point = Point { x :: Number, y :: Number }
1614

@@ -23,7 +21,7 @@ readPoint value = do
2321
y <- value ! "y" >>= readNumber
2422
pure $ Point { x: x, y: y }
2523

26-
main :: Eff (console :: CONSOLE) Unit
24+
main :: Effect Unit
2725
main = do
2826

2927
-- When trying to parse invalid JSON we catch an exception from

0 commit comments

Comments
 (0)