File tree Expand file tree Collapse file tree 4 files changed +49
-4
lines changed Expand file tree Collapse file tree 4 files changed +49
-4
lines changed Original file line number Diff line number Diff line change 11"use strict" ;
22
3- exports . peekSTArray = function ( xs ) {
3+ exports . peekSTArrayImpl = function ( xs ) {
44 return function ( i ) {
55 return function ( ) {
66 return xs [ i ] ;
77 } ;
88 } ;
99} ;
1010
11- exports . pokeSTArray = function ( xs ) {
11+ exports . pokeSTArrayImpl = function ( xs ) {
1212 return function ( i ) {
1313 return function ( a ) {
1414 return function ( ) {
Original file line number Diff line number Diff line change @@ -13,18 +13,33 @@ import Data.Array.ST (STArray)
1313import Data.Unit (Unit )
1414
1515-- | Read the value at the specified index in a mutable array.
16- foreign import peekSTArray
16+ peekSTArray
1717 :: forall a h r
1818 . Partial
1919 => STArray h a
2020 -> Int
2121 -> Eff (st :: ST h | r ) a
22+ peekSTArray = peekSTArrayImpl
23+
24+ foreign import peekSTArrayImpl
25+ :: forall a h r
26+ . STArray h a
27+ -> Int
28+ -> Eff (st :: ST h | r ) a
2229
2330-- | Change the value at the specified index in a mutable array.
24- foreign import pokeSTArray
31+ pokeSTArray
2532 :: forall a h r
2633 . Partial
2734 => STArray h a
2835 -> Int
2936 -> a
3037 -> Eff (st :: ST h | r ) Unit
38+ pokeSTArray = pokeSTArrayImpl
39+
40+ foreign import pokeSTArrayImpl
41+ :: forall a h r
42+ . STArray h a
43+ -> Int
44+ -> a
45+ -> Eff (st :: ST h | r ) Unit
Original file line number Diff line number Diff line change 1+ module Test.Data.Array.ST.Partial (testArraySTPartial ) where
2+
3+ import Prelude
4+
5+ import Control.Monad.Eff (Eff )
6+ import Control.Monad.Eff.Console (log , CONSOLE )
7+ import Control.Monad.ST (pureST )
8+
9+ import Data.Array.ST (thaw , unsafeFreeze )
10+ import Data.Array.ST.Partial (peekSTArray , pokeSTArray )
11+
12+ import Partial.Unsafe (unsafePartial )
13+
14+ import Test.Assert (assert , ASSERT )
15+
16+ testArraySTPartial :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT | eff ) Unit
17+ testArraySTPartial = do
18+
19+ log " peekSTArray should return the value at the specified index"
20+ assert $ 2 == pureST do
21+ a <- thaw [1 , 2 , 3 ]
22+ unsafePartial $ peekSTArray a 1
23+
24+ log " pokeSTArray should modify the value at the specified index"
25+ assert $ [1 , 4 , 3 ] == pureST do
26+ a <- thaw [1 , 2 , 3 ]
27+ unsafePartial $ pokeSTArray a 1 4
28+ unsafeFreeze a
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ import Test.Assert (ASSERT)
99import Test.Data.Array (testArray )
1010import Test.Data.Array.Partial (testArrayPartial )
1111import Test.Data.Array.ST (testArrayST )
12+ import Test.Data.Array.ST.Partial (testArraySTPartial )
1213
1314main :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT | eff ) Unit
1415main = do
1516 testArray
1617 testArrayST
1718 testArrayPartial
19+ testArraySTPartial
You can’t perform that action at this time.
0 commit comments