diff --git a/src/Data/Record/ST.js b/src/Data/Record/ST.js index 12b97c4..d4ad449 100644 --- a/src/Data/Record/ST.js +++ b/src/Data/Record/ST.js @@ -10,25 +10,25 @@ function copyRecord(rec) { return copy; } -exports.runSTRecord = function(rec) { +exports.run = function(rec) { return function() { return copyRecord(rec()); }; }; -exports.freezeSTRecord = function(rec) { +exports.freeze = function(rec) { return function() { return copyRecord(rec); }; }; -exports.thawSTRecord = function(rec) { +exports.thaw = function(rec) { return function() { return copyRecord(rec); }; }; -exports.unsafePeekSTRecord = function(l) { +exports.unsafePeek = function(l) { return function(rec) { return function() { return rec[l]; @@ -36,7 +36,7 @@ exports.unsafePeekSTRecord = function(l) { }; }; -exports.unsafePokeSTRecord = function(l) { +exports.unsafePoke = function(l) { return function(a) { return function(rec) { return function() { diff --git a/src/Data/Record/ST.purs b/src/Data/Record/ST.purs index 671752f..817d0fa 100644 --- a/src/Data/Record/ST.purs +++ b/src/Data/Record/ST.purs @@ -1,11 +1,18 @@ module Data.Record.ST ( STRecord + , freeze + , thaw + , peek + , poke + , run + , pureSTRecord + + -- deprecated , freezeSTRecord , thawSTRecord , peekSTRecord , pokeSTRecord , runSTRecord - , pureSTRecord ) where import Prelude @@ -21,20 +28,20 @@ import Data.Symbol (class IsSymbol, SProxy, reflectSymbol) foreign import data STRecord :: Type -> # Type -> Type -- | Freeze a mutable record, creating a copy. -foreign import freezeSTRecord :: forall h r eff. STRecord h r -> Eff (st :: ST h | eff) (Record r) +foreign import freeze :: forall h r eff. STRecord h r -> Eff (st :: ST h | eff) (Record r) -- | Thaw an immutable record, creating a copy. -foreign import thawSTRecord :: forall h r eff. Record r -> Eff (st :: ST h | eff) (STRecord h r) +foreign import thaw :: forall h r eff. Record r -> Eff (st :: ST h | eff) (STRecord h r) -- | Run an ST computation safely, constructing a record. -foreign import runSTRecord :: forall r eff. (forall h. Eff (st :: ST h | eff) (STRecord h r)) -> Eff eff (Record r) +foreign import run :: forall r eff. (forall h. Eff (st :: ST h | eff) (STRecord h r)) -> Eff eff (Record r) -- | Run an ST computation safely, constructing a record, assuming no other -- | types of effects. pureSTRecord :: forall r. (forall h eff. Eff (st :: ST h | eff) (STRecord h r)) -> Record r -pureSTRecord st = runPure (runSTRecord st) +pureSTRecord st = runPure (run st) -foreign import unsafePeekSTRecord +foreign import unsafePeek :: forall a r h eff . String -> STRecord h r @@ -42,16 +49,16 @@ foreign import unsafePeekSTRecord -- | Read the current value of a field in a mutable record, by providing a -- | type-level representative for the label which should be read. -peekSTRecord +peek :: forall l h a r r1 eff . RowCons l a r1 r => IsSymbol l => SProxy l -> STRecord h r -> Eff (st :: ST h | eff) a -peekSTRecord l = unsafePeekSTRecord (reflectSymbol l) +peek l = unsafePeek (reflectSymbol l) -foreign import unsafePokeSTRecord +foreign import unsafePoke :: forall a r h eff . String -> a @@ -60,7 +67,7 @@ foreign import unsafePokeSTRecord -- | Modify a record in place, by providing a type-level representative for the label -- | which should be updated. -pokeSTRecord +poke :: forall l h a r r1 eff . RowCons l a r1 r => IsSymbol l @@ -68,4 +75,44 @@ pokeSTRecord -> a -> STRecord h r -> Eff (st :: ST h | eff) Unit -pokeSTRecord l = unsafePokeSTRecord (reflectSymbol l) +poke l = unsafePoke (reflectSymbol l) + +freezeSTRecord + :: forall h r eff + . Warn "Deprecated `freezeSTRecord`. Use `freeze` instead." + => STRecord h r -> Eff (st :: ST h | eff) (Record r) +freezeSTRecord = freeze + +thawSTRecord + :: forall h r eff + . Warn "Deprecated `thawSTRecord`. Use `thaw` instead." + => Record r -> Eff (st :: ST h | eff) (STRecord h r) +thawSTRecord = thaw + +peekSTRecord + :: forall l h a r r1 eff + . Warn "Deprecated `peekSTRecord`. Use `peek` instead." + => RowCons l a r1 r + => IsSymbol l + => SProxy l + -> STRecord h r + -> Eff (st :: ST h | eff) a +peekSTRecord = peek + +pokeSTRecord + :: forall l h a r r1 eff + . Warn "Deprecated `pokeSTRecord`. Use `poke` instead." + => RowCons l a r1 r + => IsSymbol l + => SProxy l + -> a + -> STRecord h r + -> Eff (st :: ST h | eff) Unit +pokeSTRecord = poke + +runSTRecord + :: forall r eff + . Warn "Deprecated `runSTRecord`. Use `run` instead." + => (forall h. Eff (st :: ST h | eff) (STRecord h r)) + -> Eff eff (Record r) +runSTRecord = run diff --git a/test/Main.purs b/test/Main.purs index 1c2a34b..92c1e40 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -5,7 +5,7 @@ import Prelude import Control.Monad.Eff (Eff) import Data.Record (delete, equal, get, insert, modify, rename, set) import Data.Record.Builder as Builder -import Data.Record.ST (pokeSTRecord, pureSTRecord, thawSTRecord) +import Data.Record.ST (poke, pureSTRecord, thaw) import Data.Record.Unsafe (unsafeHas) import Data.Symbol (SProxy(..)) import Test.Assert (ASSERT, assert') @@ -38,12 +38,12 @@ main = do not $ unsafeHas "b" { a: 42 } let stTest1 = pureSTRecord do - rec <- thawSTRecord { x: 41, y: "" } - pokeSTRecord x 42 rec - pokeSTRecord y "testing" rec + rec <- thaw { x: 41, y: "" } + poke x 42 rec + poke y "testing" rec pure rec - assert' "pokeSTRecord" $ + assert' "poke" $ stTest1.x == 42 && stTest1.y == "testing" let testBuilder = Builder.build (Builder.insert x 42