Skip to content

Commit 4c35571

Browse files
authored
Updates for 0.12 (#42)
1 parent c6a091f commit 4c35571

File tree

6 files changed

+71
-86
lines changed

6 files changed

+71
-86
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "eslint src && pulp build -- --censor-lib --strict",
6-
"test": "pulp test"
6+
"test": "pulp test --check-main-type Effect.Effect"
77
},
88
"devDependencies": {
99
"eslint": "^4.19.1",

src/Data/Record.purs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Data.Function.Uncurried (runFn2, runFn3)
1414
import Data.Record.Unsafe (unsafeGetFn, unsafeSetFn, unsafeDeleteFn)
1515
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
1616
import Prelude (class Eq, (&&), (==))
17-
import Type.Row (class RowLacks, class RowToList, Cons, Nil, RLProxy(RLProxy), kind RowList)
17+
import Type.Row (class Lacks, class Cons, class RowToList, Cons, Nil, RLProxy(RLProxy), kind RowList)
1818

1919
-- | Get a property for a label which is specified using a value-level proxy for
2020
-- | a type-level string.
@@ -27,7 +27,7 @@ import Type.Row (class RowLacks, class RowToList, Cons, Nil, RLProxy(RLProxy), k
2727
get
2828
:: forall r r' l a
2929
. IsSymbol l
30-
=> RowCons l a r' r
30+
=> Cons l a r' r
3131
=> SProxy l
3232
-> Record r
3333
-> a
@@ -45,8 +45,8 @@ get l r = runFn2 unsafeGetFn (reflectSymbol l) r
4545
set
4646
:: forall r1 r2 r l a b
4747
. IsSymbol l
48-
=> RowCons l a r r1
49-
=> RowCons l b r r2
48+
=> Cons l a r r1
49+
=> Cons l b r r2
5050
=> SProxy l
5151
-> b
5252
-> Record r1
@@ -65,8 +65,8 @@ set l b r = runFn3 unsafeSetFn (reflectSymbol l) b r
6565
modify
6666
:: forall r1 r2 r l a b
6767
. IsSymbol l
68-
=> RowCons l a r r1
69-
=> RowCons l b r r2
68+
=> Cons l a r r1
69+
=> Cons l b r r2
7070
=> SProxy l
7171
-> (a -> b)
7272
-> Record r1
@@ -80,13 +80,13 @@ modify l f r = set l (f (get l r)) r
8080
-- |
8181
-- | ```purescript
8282
-- | insert (SProxy :: SProxy "x")
83-
-- | :: forall r a. RowLacks "x" r => a -> { | r } -> { x :: a | r }
83+
-- | :: forall r a. Lacks "x" r => a -> { | r } -> { x :: a | r }
8484
-- | ```
8585
insert
8686
:: forall r1 r2 l a
8787
. IsSymbol l
88-
=> RowLacks l r1
89-
=> RowCons l a r1 r2
88+
=> Lacks l r1
89+
=> Cons l a r1 r2
9090
=> SProxy l
9191
-> a
9292
-> Record r1
@@ -103,13 +103,13 @@ insert l a r = runFn3 unsafeSetFn (reflectSymbol l) a r
103103
-- |
104104
-- | ```purescript
105105
-- | delete (SProxy :: SProxy "x")
106-
-- | :: forall r a. RowLacks "x" r => { x :: a | r } -> { | r }
106+
-- | :: forall r a. Lacks "x" r => { x :: a | r } -> { | r }
107107
-- | ```
108108
delete
109109
:: forall r1 r2 l a
110110
. IsSymbol l
111-
=> RowLacks l r1
112-
=> RowCons l a r1 r2
111+
=> Lacks l r1
112+
=> Cons l a r1 r2
113113
=> SProxy l
114114
-> Record r2
115115
-> Record r1
@@ -125,15 +125,15 @@ delete l r = runFn2 unsafeDeleteFn (reflectSymbol l) r
125125
-- |
126126
-- | ```purescript
127127
-- | rename (SProxy :: SProxy "x") (SProxy :: SProxy "y")
128-
-- | :: forall a r. RowLacks "x" r => RowLacks "y" r => { x :: a | r} -> { y :: a | r}
128+
-- | :: forall a r. Lacks "x" r => Lacks "y" r => { x :: a | r} -> { y :: a | r}
129129
-- | ```
130130
rename :: forall prev next ty input inter output
131131
. IsSymbol prev
132132
=> IsSymbol next
133-
=> RowCons prev ty inter input
134-
=> RowLacks prev inter
135-
=> RowCons next ty inter output
136-
=> RowLacks next inter
133+
=> Cons prev ty inter input
134+
=> Lacks prev inter
135+
=> Cons next ty inter output
136+
=> Lacks next inter
137137
=> SProxy prev
138138
-> SProxy next
139139
-> Record input
@@ -158,7 +158,7 @@ instance equalFieldsCons
158158
::
159159
( IsSymbol name
160160
, Eq ty
161-
, RowCons name ty tailRow row
161+
, Cons name ty tailRow row
162162
, EqualFields tail row
163163
) => EqualFields (Cons name ty tail) row where
164164
equalFields _ a b = get' a == get' b && equalRest a b

src/Data/Record/Builder.purs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Data.Record.Builder
1111
import Prelude
1212

1313
import Data.Symbol (class IsSymbol, SProxy, reflectSymbol)
14-
import Type.Row (class RowLacks)
14+
import Type.Row as Row
1515

1616
foreign import copyRecord :: forall r1. Record r1 -> Record r1
1717
foreign import unsafeInsert :: forall a r1 r2. String -> a -> Record r1 -> Record r2
@@ -43,8 +43,8 @@ derive newtype instance categoryBuilder :: Category Builder
4343
-- | Build by inserting a new field.
4444
insert
4545
:: forall l a r1 r2
46-
. RowCons l a r1 r2
47-
=> RowLacks l r1
46+
. Row.Cons l a r1 r2
47+
=> Row.Lacks l r1
4848
=> IsSymbol l
4949
=> SProxy l
5050
-> a
@@ -54,8 +54,8 @@ insert l a = Builder \r1 -> unsafeInsert (reflectSymbol l) a r1
5454
-- | Build by modifying an existing field.
5555
modify
5656
:: forall l a b r r1 r2
57-
. RowCons l a r r1
58-
=> RowCons l b r r2
57+
. Row.Cons l a r r1
58+
=> Row.Cons l b r r2
5959
=> IsSymbol l
6060
=> SProxy l
6161
-> (a -> b)
@@ -66,8 +66,8 @@ modify l f = Builder \r1 -> unsafeModify (reflectSymbol l) f r1
6666
delete
6767
:: forall l a r1 r2
6868
. IsSymbol l
69-
=> RowLacks l r1
70-
=> RowCons l a r1 r2
69+
=> Row.Lacks l r1
70+
=> Row.Cons l a r1 r2
7171
=> SProxy l
7272
-> Builder (Record r2) (Record r1)
7373
delete l = Builder \r2 -> unsafeDelete (reflectSymbol l) r2
@@ -76,10 +76,10 @@ delete l = Builder \r2 -> unsafeDelete (reflectSymbol l) r2
7676
rename :: forall l1 l2 a r1 r2 r3
7777
. IsSymbol l1
7878
=> IsSymbol l2
79-
=> RowCons l1 a r2 r1
80-
=> RowLacks l1 r2
81-
=> RowCons l2 a r2 r3
82-
=> RowLacks l2 r2
79+
=> Row.Cons l1 a r2 r1
80+
=> Row.Lacks l1 r2
81+
=> Row.Cons l2 a r2 r3
82+
=> Row.Lacks l2 r2
8383
=> SProxy l1
8484
-> SProxy l2
8585
-> Builder (Record r1) (Record r3)
@@ -88,7 +88,7 @@ rename l1 l2 = Builder \r1 -> unsafeRename (reflectSymbol l1) (reflectSymbol l2)
8888
-- | Build by merging existing fields from another record.
8989
merge
9090
:: forall r1 r2 r3
91-
. Union r1 r2 r3
91+
. Row.Union r1 r2 r3
9292
=> Record r2
9393
-> Builder (Record r1) (Record r3)
9494
merge r2 = Builder \r1 -> unsafeMerge r1 r2

src/Data/Record/ST.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,27 @@ function copyRecord(rec) {
1010
return copy;
1111
}
1212

13-
exports.runSTRecord = function(rec) {
14-
return function() {
15-
return copyRecord(rec());
16-
};
17-
};
18-
19-
exports.freezeSTRecord = function(rec) {
13+
exports.freeze = function(rec) {
2014
return function() {
2115
return copyRecord(rec);
2216
};
2317
};
2418

25-
exports.thawSTRecord = function(rec) {
19+
exports.thaw = function(rec) {
2620
return function() {
2721
return copyRecord(rec);
2822
};
2923
};
3024

31-
exports.unsafePeekSTRecord = function(l) {
25+
exports.unsafePeek = function(l) {
3226
return function(rec) {
3327
return function() {
3428
return rec[l];
3529
};
3630
};
3731
};
3832

39-
exports.unsafePokeSTRecord = function(l) {
33+
exports.unsafePoke = function(l) {
4034
return function(a) {
4135
return function(rec) {
4236
return function() {

src/Data/Record/ST.purs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,61 @@
11
module Data.Record.ST
22
( STRecord
3-
, freezeSTRecord
4-
, thawSTRecord
5-
, peekSTRecord
6-
, pokeSTRecord
7-
, runSTRecord
8-
, pureSTRecord
3+
, freeze
4+
, thaw
5+
, peek
6+
, poke
97
) where
108

119
import Prelude
1210

13-
import Control.Monad.Eff (Eff, runPure)
14-
import Control.Monad.ST (ST)
11+
import Control.Monad.ST (ST, kind Region)
1512
import Data.Symbol (class IsSymbol, SProxy, reflectSymbol)
13+
import Prim.Row as Row
1614

1715
-- | A value of type `STRecord h r` represents a mutable record with fields `r`,
1816
-- | belonging to the state thread `h`.
1917
-- |
20-
-- | Create values of type `STRecord` using `thawSTRecord`.
21-
foreign import data STRecord :: Type -> # Type -> Type
18+
-- | Create values of type `STRecord` using `thaw`.
19+
foreign import data STRecord :: Region -> # Type -> Type
2220

2321
-- | Freeze a mutable record, creating a copy.
24-
foreign import freezeSTRecord :: forall h r eff. STRecord h r -> Eff (st :: ST h | eff) (Record r)
22+
foreign import freeze :: forall h r. STRecord h r -> ST h (Record r)
2523

2624
-- | Thaw an immutable record, creating a copy.
27-
foreign import thawSTRecord :: forall h r eff. Record r -> Eff (st :: ST h | eff) (STRecord h r)
25+
foreign import thaw :: forall h r. Record r -> ST h (STRecord h r)
2826

29-
-- | Run an ST computation safely, constructing a record.
30-
foreign import runSTRecord :: forall r eff. (forall h. Eff (st :: ST h | eff) (STRecord h r)) -> Eff eff (Record r)
31-
32-
-- | Run an ST computation safely, constructing a record, assuming no other
33-
-- | types of effects.
34-
pureSTRecord :: forall r. (forall h eff. Eff (st :: ST h | eff) (STRecord h r)) -> Record r
35-
pureSTRecord st = runPure (runSTRecord st)
36-
37-
foreign import unsafePeekSTRecord
38-
:: forall a r h eff
27+
foreign import unsafePeek
28+
:: forall a r h
3929
. String
4030
-> STRecord h r
41-
-> Eff (st :: ST h | eff) a
31+
-> ST h a
4232

4333
-- | Read the current value of a field in a mutable record, by providing a
4434
-- | type-level representative for the label which should be read.
45-
peekSTRecord
46-
:: forall l h a r r1 eff
47-
. RowCons l a r1 r
35+
peek
36+
:: forall l h a r r1
37+
. Row.Cons l a r1 r
4838
=> IsSymbol l
4939
=> SProxy l
5040
-> STRecord h r
51-
-> Eff (st :: ST h | eff) a
52-
peekSTRecord l = unsafePeekSTRecord (reflectSymbol l)
41+
-> ST h a
42+
peek l = unsafePeek (reflectSymbol l)
5343

54-
foreign import unsafePokeSTRecord
55-
:: forall a r h eff
44+
foreign import unsafePoke
45+
:: forall a r h
5646
. String
5747
-> a
5848
-> STRecord h r
59-
-> Eff (st :: ST h | eff) Unit
49+
-> ST h Unit
6050

6151
-- | Modify a record in place, by providing a type-level representative for the label
6252
-- | which should be updated.
63-
pokeSTRecord
64-
:: forall l h a r r1 eff
65-
. RowCons l a r1 r
53+
poke
54+
:: forall l h a r r1
55+
. Row.Cons l a r1 r
6656
=> IsSymbol l
6757
=> SProxy l
6858
-> a
6959
-> STRecord h r
70-
-> Eff (st :: ST h | eff) Unit
71-
pokeSTRecord l = unsafePokeSTRecord (reflectSymbol l)
60+
-> ST h Unit
61+
poke l = unsafePoke (reflectSymbol l)

test/Main.purs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ module Test.Main where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
5+
import Effect (Effect)
66
import Data.Record (delete, equal, get, insert, modify, rename, set)
77
import Data.Record.Builder as Builder
8-
import Data.Record.ST (pokeSTRecord, pureSTRecord, thawSTRecord)
8+
import Control.Monad.ST (run) as ST
9+
import Data.Record.ST (poke, thaw, freeze) as ST
910
import Data.Record.Unsafe (unsafeHas)
1011
import Data.Symbol (SProxy(..))
11-
import Test.Assert (ASSERT, assert')
12+
import Test.Assert (assert')
1213

13-
main :: Eff (assert :: ASSERT) Unit
14+
main :: Effect Unit
1415
main = do
1516
let x = SProxy :: SProxy "x"
1617
y = SProxy :: SProxy "y"
@@ -37,11 +38,11 @@ main = do
3738
assert' "unsafeHas2" $
3839
not $ unsafeHas "b" { a: 42 }
3940

40-
let stTest1 = pureSTRecord do
41-
rec <- thawSTRecord { x: 41, y: "" }
42-
pokeSTRecord x 42 rec
43-
pokeSTRecord y "testing" rec
44-
pure rec
41+
let stTest1 = ST.run do
42+
rec <- ST.thaw { x: 41, y: "" }
43+
ST.poke x 42 rec
44+
ST.poke y "testing" rec
45+
ST.freeze rec
4546

4647
assert' "pokeSTRecord" $
4748
stTest1.x == 42 && stTest1.y == "testing"

0 commit comments

Comments
 (0)