Skip to content

Commit 8d09843

Browse files
committed
Upgrade to purescript-codec v6 and purescript-codec-argonaut v10
1 parent 01360b4 commit 8d09843

10 files changed

+166
-68
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
description = "iios";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11";
6+
easy-purescript-nix = {
7+
url = "github:justinwoo/easy-purescript-nix";
8+
flake = false;
9+
};
10+
flake-compat = {
11+
url = "github:edolstra/flake-compat";
12+
flake = false;
13+
};
14+
};
15+
16+
outputs = { self, nixpkgs, easy-purescript-nix, ... }@inputs:
17+
let
18+
name = "iios";
19+
20+
supportedSystems = [
21+
"aarch64-darwin"
22+
"x86_64-darwin"
23+
"x86_64-linux"
24+
];
25+
26+
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
27+
in
28+
{
29+
devShell = forAllSystems (system:
30+
let
31+
pkgs = import nixpkgs { inherit system; };
32+
33+
easy-ps = import easy-purescript-nix { inherit pkgs; };
34+
in
35+
pkgs.mkShell {
36+
inherit name;
37+
buildInputs = (with pkgs; [
38+
nodejs-18_x
39+
nixpkgs-fmt
40+
]) ++ (with easy-ps; [
41+
purs
42+
purs-tidy
43+
psa
44+
spago
45+
purescript-language-server
46+
]) ++ (pkgs.lib.optionals (system == "aarch64-darwin")
47+
(with pkgs.darwin.apple_sdk.frameworks; [
48+
Cocoa
49+
CoreServices
50+
]));
51+
});
52+
};
53+
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"author": "Hardy Jones <[email protected]>",
1111
"license": "MIT",
1212
"devDependencies": {
13-
"bower": "^1.8.8",
14-
"purescript": "^0.14.0",
13+
"purescript": "^0.15.0",
1514
"purescript-psa": "^0.8.2",
1615
"purty": "^7.0.0"
1716
}

packages.dhall

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let upstream =
2-
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220901/packages.dhall
3-
sha256:f1531b29c21ac437ffe5666c1b6cc76f0a9c29d3c9d107ff047aa2567744994f
2+
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221229/packages.dhall
3+
sha256:a6af1091425f806ec0da34934bb6c0ab0ac1598620bbcbb60a7d463354e7d87c
44

5-
in upstream
5+
in upstream

spago.dhall

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
, "foldable-traversable"
1313
, "foreign"
1414
, "foreign-object"
15+
, "functors"
1516
, "identity"
1617
, "lists"
1718
, "maybe"
1819
, "prelude"
19-
, "profunctor"
2020
, "record"
2121
, "simple-json"
2222
, "spec"
23-
, "strings"
2423
, "transformers"
2524
, "tuples"
2625
, "unsafe-coerce"

src/Option.purs

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ module Option
125125
import Prelude
126126
import Prim hiding (Record)
127127
import Control.Monad.Except as Control.Monad.Except
128-
import Control.Monad.Reader.Trans as Control.Monad.Reader.Trans
129-
import Control.Monad.Writer as Control.Monad.Writer
130-
import Control.Monad.Writer.Class as Control.Monad.Writer.Class
131128
import Data.Argonaut.Core as Data.Argonaut.Core
132129
import Data.Argonaut.Decode.Class as Data.Argonaut.Decode.Class
133130
import Data.Argonaut.Decode.Error as Data.Argonaut.Decode.Error
@@ -137,9 +134,9 @@ import Data.Codec.Argonaut as Data.Codec.Argonaut
137134
import Data.Codec.Argonaut.Compat as Data.Codec.Argonaut.Compat
138135
import Data.Either as Data.Either
139136
import Data.Identity as Data.Identity
137+
import Data.List ((:))
140138
import Data.List as Data.List
141139
import Data.Maybe as Data.Maybe
142-
import Data.Profunctor.Star as Data.Profunctor.Star
143140
import Data.Show as Data.Show
144141
import Data.Symbol as Data.Symbol
145142
import Data.Tuple as Data.Tuple
@@ -1420,9 +1417,7 @@ instance jsonCodecRecordRequiredOptional ::
14201417
where
14211418
codec :: Data.Codec.Argonaut.JPropCodec (Record required optional)
14221419
codec =
1423-
Data.Codec.GCodec
1424-
(Control.Monad.Reader.Trans.ReaderT decode)
1425-
(Data.Profunctor.Star.Star encode)
1420+
Data.Codec.codec decode encode
14261421

14271422
decode ::
14281423
Foreign.Object.Object Data.Argonaut.Core.Json ->
@@ -1441,13 +1436,9 @@ instance jsonCodecRecordRequiredOptional ::
14411436

14421437
encode ::
14431438
Record required optional ->
1444-
Control.Monad.Writer.Writer
1445-
(Data.List.List (Data.Tuple.Tuple String Data.Argonaut.Core.Json))
1446-
(Record required optional)
1447-
encode record = do
1448-
Control.Monad.Writer.Class.tell (Data.Codec.encode requiredCodec (required record))
1449-
Control.Monad.Writer.Class.tell (Data.Codec.encode optionalCodec (optional record))
1450-
pure record
1439+
(Data.List.List (Data.Tuple.Tuple String Data.Argonaut.Core.Json))
1440+
encode record =
1441+
Data.List.concat (Data.Codec.encode requiredCodec (required record) : (Data.Codec.encode optionalCodec (optional record)) : Data.List.Nil)
14511442

14521443
optionalCodec :: Data.Codec.Argonaut.JPropCodec (Option optional)
14531444
optionalCodec = jsonCodecOption optionalProxy record'
@@ -1479,10 +1470,10 @@ instance jsonCodecOptionNil :: JsonCodecOption Prim.RowList.Nil record option wh
14791470
Prim.Record record ->
14801471
Data.Codec.Argonaut.JPropCodec (Option option)
14811472
jsonCodecOption _ _ =
1482-
Data.Codec.mapCodec
1483-
(\_ -> Data.Either.Right empty)
1484-
(\_ -> {})
1485-
Data.Codec.Argonaut.record
1473+
Data.Codec.codec
1474+
((\_ -> Data.Either.Right empty) <=< Data.Codec.Argonaut.decode Data.Codec.Argonaut.record)
1475+
(Data.Codec.Argonaut.encode Data.Codec.Argonaut.record <<< \_ -> {})
1476+
14861477
else instance jsonCodecOptionCons ::
14871478
( Data.Symbol.IsSymbol label
14881479
, JsonCodecOption list record option'
@@ -1497,9 +1488,7 @@ else instance jsonCodecOptionCons ::
14971488
Prim.Record record ->
14981489
Data.Codec.Argonaut.JPropCodec (Option option)
14991490
jsonCodecOption _ record =
1500-
Data.Codec.GCodec
1501-
(Control.Monad.Reader.Trans.ReaderT decode)
1502-
(Data.Profunctor.Star.Star encode)
1491+
Data.Codec.codec decode encode
15031492
where
15041493
codec :: Data.Codec.Argonaut.JsonCodec value
15051494
codec = Record.get label record
@@ -1519,19 +1508,18 @@ else instance jsonCodecOptionCons ::
15191508

15201509
encode ::
15211510
Option option ->
1522-
Control.Monad.Writer.Writer (Data.List.List (Data.Tuple.Tuple String Data.Argonaut.Core.Json)) (Option option)
1523-
encode option = do
1524-
case get label option of
1525-
Data.Maybe.Just value ->
1526-
Control.Monad.Writer.Class.tell
1527-
( Data.List.Cons
1528-
(Data.Tuple.Tuple key (Data.Codec.Argonaut.encode codec value))
1529-
Data.List.Nil
1530-
)
1531-
Data.Maybe.Nothing -> pure unit
1532-
Control.Monad.Writer.Class.tell
1533-
(Data.Codec.Argonaut.encode option' (delete label option))
1534-
pure option
1511+
(Data.List.List (Data.Tuple.Tuple String Data.Argonaut.Core.Json))
1512+
encode option =
1513+
let a = case get label option of
1514+
Data.Maybe.Just value ->
1515+
( Data.List.Cons
1516+
(Data.Tuple.Tuple key (Data.Codec.Argonaut.encode codec value))
1517+
Data.List.Nil
1518+
)
1519+
Data.Maybe.Nothing -> Data.List.Nil
1520+
in
1521+
Data.List.concat (a : (Data.Codec.Argonaut.encode option' (delete label option)) : Data.List.Nil)
1522+
-- pure option
15351523

15361524
key :: String
15371525
key = Data.Symbol.reflectSymbol label
@@ -1563,10 +1551,10 @@ instance jsonCodecRequiredNil :: JsonCodecRequired Prim.RowList.Nil record () wh
15631551
Prim.Record record ->
15641552
Data.Codec.Argonaut.JPropCodec (Prim.Record ())
15651553
jsonCodecRequired _ _ =
1566-
Data.Codec.mapCodec
1567-
(\_ -> Data.Either.Right {})
1568-
(\_ -> {})
1569-
Data.Codec.Argonaut.record
1554+
Data.Codec.codec
1555+
(Data.Codec.Argonaut.decode Data.Codec.Argonaut.record)
1556+
(Data.Codec.Argonaut.encode Data.Codec.Argonaut.record)
1557+
15701558
else instance jsonCodecRequiredCons ::
15711559
( Data.Symbol.IsSymbol label
15721560
, JsonCodecRequired list record required'
@@ -1581,9 +1569,7 @@ else instance jsonCodecRequiredCons ::
15811569
Prim.Record record ->
15821570
Data.Codec.Argonaut.JPropCodec (Prim.Record required)
15831571
jsonCodecRequired _ record =
1584-
Data.Codec.GCodec
1585-
(Control.Monad.Reader.Trans.ReaderT decode)
1586-
(Data.Profunctor.Star.Star encode)
1572+
Data.Codec.codec decode encode
15871573
where
15881574
codec :: Data.Codec.Argonaut.JsonCodec value
15891575
codec = Record.get label record
@@ -1600,17 +1586,12 @@ else instance jsonCodecRequiredCons ::
16001586
Data.Maybe.Nothing -> Data.Either.Left (Data.Codec.Argonaut.AtKey key Data.Codec.Argonaut.MissingValue)
16011587

16021588
encode ::
1603-
Prim.Record required ->
1604-
Control.Monad.Writer.Writer (Data.List.List (Data.Tuple.Tuple String Data.Argonaut.Core.Json)) (Prim.Record required)
1589+
Prim.Record required -> Data.List.List (Data.Tuple.Tuple String Data.Argonaut.Core.Json)
16051590
encode required' = do
1606-
Control.Monad.Writer.Class.tell
1607-
( Data.List.Cons
1591+
Data.List.concat ((Data.List.Cons
16081592
(Data.Tuple.Tuple key (Data.Codec.Argonaut.encode codec (Record.get label required')))
16091593
Data.List.Nil
1610-
)
1611-
Control.Monad.Writer.Class.tell
1612-
(Data.Codec.Argonaut.encode requiredCodec (Record.delete label required'))
1613-
pure required'
1594+
) : (Data.Codec.Argonaut.encode requiredCodec (Record.delete label required')): Data.List.Nil)
16141595

16151596
key :: String
16161597
key = Data.Symbol.reflectSymbol label
@@ -2779,7 +2760,7 @@ jsonCodec ::
27792760
String ->
27802761
Prim.Record record ->
27812762
Data.Codec.Argonaut.JsonCodec (Option optional)
2782-
jsonCodec name record' = Data.Codec.basicCodec decode encode
2763+
jsonCodec name record' = Data.Codec.codec' decode encode
27832764
where
27842765
codec :: Data.Codec.Argonaut.JsonCodec (Record () optional)
27852766
codec = jsonCodec' name record'

test/HowTo.MakeAFunctionWithOptionalValues.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module HowTo.MakeAFunctionWithOptionalValues
55
) where
66

77
import Prelude
8+
import Type.Proxy as Type
9+
import Data.Functor.Product as Data
810
import Data.Maybe as Data.Maybe
911
import Data.Symbol as Data.Symbol
1012
import Option as Option
@@ -15,12 +17,12 @@ greeting :: Option.Option ( name :: String, title :: String ) -> String
1517
greeting option = "Hello, " <> title' <> name'
1618
where
1719
name' :: String
18-
name' = case Option.get (Data.Symbol.SProxy :: _ "name") option of
20+
name' = case Option.get (Type.Proxy :: _ "name") option of
1921
Data.Maybe.Just name -> name
2022
Data.Maybe.Nothing -> "World"
2123

2224
title' :: String
23-
title' = case Option.get (Data.Symbol.SProxy :: _ "title") option of
25+
title' = case Option.get (Type.Proxy :: _ "title") option of
2426
Data.Maybe.Just title -> title <> " "
2527
Data.Maybe.Nothing -> ""
2628

test/HowTo.MakeAFunctionWithOptionalValuesFromARecord.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module HowTo.MakeAFunctionWithOptionalValuesFromARecord
55
) where
66

77
import Prelude
8+
import Type.Proxy as Type
89
import Data.Maybe as Data.Maybe
910
import Data.Symbol as Data.Symbol
1011
import Option as Option
@@ -19,15 +20,15 @@ greeting ::
1920
greeting record = "Hello, " <> title' <> name'
2021
where
2122
name' :: String
22-
name' = case Option.get (Data.Symbol.SProxy :: _ "name") option of
23+
name' = case Option.get (Type.Proxy :: _ "name") option of
2324
Data.Maybe.Just name -> name
2425
Data.Maybe.Nothing -> "World"
2526

2627
option :: Option.Option ( name :: String, title :: String )
2728
option = Option.fromRecord record
2829

2930
title' :: String
30-
title' = case Option.get (Data.Symbol.SProxy :: _ "title") option of
31+
title' = case Option.get (Type.Proxy :: _ "title") option of
3132
Data.Maybe.Just title -> title <> " "
3233
Data.Maybe.Nothing -> ""
3334

0 commit comments

Comments
 (0)