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 1
1
"use strict" ;
2
2
3
- exports . peekSTArray = function ( xs ) {
3
+ exports . peekSTArrayImpl = function ( xs ) {
4
4
return function ( i ) {
5
5
return function ( ) {
6
6
return xs [ i ] ;
7
7
} ;
8
8
} ;
9
9
} ;
10
10
11
- exports . pokeSTArray = function ( xs ) {
11
+ exports . pokeSTArrayImpl = function ( xs ) {
12
12
return function ( i ) {
13
13
return function ( a ) {
14
14
return function ( ) {
Original file line number Diff line number Diff line change @@ -13,18 +13,33 @@ import Data.Array.ST (STArray)
13
13
import Data.Unit (Unit )
14
14
15
15
-- | Read the value at the specified index in a mutable array.
16
- foreign import peekSTArray
16
+ peekSTArray
17
17
:: forall a h r
18
18
. Partial
19
19
=> STArray h a
20
20
-> Int
21
21
-> 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
22
29
23
30
-- | Change the value at the specified index in a mutable array.
24
- foreign import pokeSTArray
31
+ pokeSTArray
25
32
:: forall a h r
26
33
. Partial
27
34
=> STArray h a
28
35
-> Int
29
36
-> a
30
37
-> 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)
9
9
import Test.Data.Array (testArray )
10
10
import Test.Data.Array.Partial (testArrayPartial )
11
11
import Test.Data.Array.ST (testArrayST )
12
+ import Test.Data.Array.ST.Partial (testArraySTPartial )
12
13
13
14
main :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT | eff ) Unit
14
15
main = do
15
16
testArray
16
17
testArrayST
17
18
testArrayPartial
19
+ testArraySTPartial
You can’t perform that action at this time.
0 commit comments