-
Notifications
You must be signed in to change notification settings - Fork 2
/
ioarray.gs
40 lines (33 loc) · 1.62 KB
/
ioarray.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
------------------------------------------------------------------------------
-- This file contains a Gofer implementation of the monadic array
-- primitives for Lazy state threads, as described in the PLDI '94
-- paper by John Launchbury and Simon Peyton Jones, using new Gofer
-- primitives added in Gofer 2.30.
--
-- This file must be loaded only after both array.gs and iomonad.gs,
-- and requires the standard, or cc prelude.
--
-- You will not be able to use this file unless the version of Gofer that
-- is installed on your machine has been compiled with the IO_MONAD flag
-- and the HASKELL_ARRAYS flag set to 1.
--
-- Mark P Jones, 1994
------------------------------------------------------------------------------
module LazyStateArr( newArr, readArr, writeArr, freezeArr ) where
primitive primSTNewArr "primSTNewArr"
:: (a -> Int) -> (a,a) -> b -> ST s (MutArr s a b)
primitive primSTReadArr "primSTReadArr"
:: ((a,a) -> a -> Int) -> MutArr s a b -> a -> ST s b
primitive primSTWriteArr "primSTWriteArr"
:: ((a,a) -> a -> Int) -> MutArr s a b -> a -> b -> ST s ()
primitive primSTFreeze "primSTFreeze"
:: MutArr s a b -> ST s (Array a b)
newArr :: Ix a => (a,a) -> b -> ST s (MutArr s a b)
newArr bounds = primSTNewArr (index bounds) bounds
readArr :: Ix a => MutArr s a b -> a -> ST s b
readArr = primSTReadArr index
writeArr :: Ix a => MutArr s a b -> a -> b -> ST s ()
writeArr = primSTWriteArr index
freezeArr :: Ix a => MutArr s a b -> ST s (Array a b)
freezeArr = primSTFreeze
------------------------------------------------------------------------------