@@ -37,74 +37,74 @@ import Node.Buffer as Buffer
37
37
import Node.Encoding (Encoding , encodingToNode )
38
38
import Unsafe.Coerce (unsafeCoerce )
39
39
40
- -- | A type class for mutable buffers `b ` where operations on those buffers are
41
- -- | represented by a particular effect type `e `.
42
- class MutableBuffer b e | e -> b , b -> e where
40
+ -- | A type class for mutable buffers `buf ` where operations on those buffers are
41
+ -- | represented by a particular monadic effect type `m `.
42
+ class Monad m <= MutableBuffer buf m | m -> buf , buf -> m where
43
43
44
44
-- | Creates a new buffer of the specified size.
45
- create :: Int -> e b
45
+ create :: Int -> m buf
46
46
47
47
-- | Creates an immutable copy of a mutable buffer.
48
- freeze :: b -> e Buffer
48
+ freeze :: buf -> m Buffer
49
49
50
50
-- | Creates a mutable copy of an immutable buffer.
51
- thaw :: Buffer -> e b
51
+ thaw :: Buffer -> m buf
52
52
53
53
-- | Creates a new buffer from an array of octets, sized to match the array.
54
- fromArray :: Array Octet -> e b
54
+ fromArray :: Array Octet -> m buf
55
55
56
56
-- | Creates a new buffer from a string with the specified encoding, sized to
57
57
-- | match the string.
58
- fromString :: String -> Encoding -> e b
58
+ fromString :: String -> Encoding -> m buf
59
59
60
60
-- | Creates a buffer view from a JS ArrayByffer without copying data.
61
- fromArrayBuffer :: ArrayBuffer -> e b
61
+ fromArrayBuffer :: ArrayBuffer -> m buf
62
62
63
63
-- | Copies the data in the buffer to a new JS ArrayBuffer
64
- toArrayBuffer :: b -> e ArrayBuffer
64
+ toArrayBuffer :: buf -> m ArrayBuffer
65
65
66
66
-- | Reads a numeric value from a buffer at the specified offset.
67
- read :: BufferValueType -> Offset -> b -> e Int
67
+ read :: BufferValueType -> Offset -> buf -> m Int
68
68
69
69
-- | Reads a section of a buffer as a string with the specified encoding.
70
- readString :: Encoding -> Offset -> Offset -> b -> e String
70
+ readString :: Encoding -> Offset -> Offset -> buf -> m String
71
71
72
72
-- | Reads the buffer as a string with the specified encoding.
73
- toString :: Encoding -> b -> e String
73
+ toString :: Encoding -> buf -> m String
74
74
75
75
-- | Writes a numeric value to a buffer at the specified offset.
76
- write :: BufferValueType -> Int -> Offset -> b -> e Unit
76
+ write :: BufferValueType -> Int -> Offset -> buf -> m Unit
77
77
78
78
-- | Writes octets from a string to a buffer at the specified offset. Multi-byte
79
79
-- | characters will not be written to the buffer if there is not enough capacity
80
80
-- | to write them fully. The number of bytes written is returned.
81
- writeString :: Encoding -> Offset -> Int -> String -> b -> e Int
81
+ writeString :: Encoding -> Offset -> Int -> String -> buf -> m Int
82
82
83
83
-- | Creates an array of octets from a buffer's contents.
84
- toArray :: b -> e (Array Octet )
84
+ toArray :: buf -> m (Array Octet )
85
85
86
86
-- | Reads an octet from a buffer at the specified offset.
87
- getAtOffset :: Offset -> b -> e (Maybe Octet )
87
+ getAtOffset :: Offset -> buf -> m (Maybe Octet )
88
88
89
89
-- | Writes an octet in the buffer at the specified offset.
90
- setAtOffset :: Octet -> Offset -> b -> e Unit
90
+ setAtOffset :: Octet -> Offset -> buf -> m Unit
91
91
92
92
-- | Returns the size of a buffer.
93
- size :: b -> e Int
93
+ size :: buf -> m Int
94
94
95
95
-- | Concatenates a list of buffers.
96
- concat :: Array b -> e b
96
+ concat :: Array buf -> m buf
97
97
98
98
-- | Concatenates a list of buffers, combining them into a new buffer of the
99
99
-- | specified length.
100
- concat' :: Array b -> Int -> e b
100
+ concat' :: Array buf -> Int -> m buf
101
101
102
102
-- | Copies a section of a source buffer into a target buffer at the specified
103
103
-- | offset, and returns the number of octets copied.
104
- copy :: Offset -> Offset -> b -> Offset -> b -> e Int
104
+ copy :: Offset -> Offset -> buf -> Offset -> buf -> m Int
105
105
106
106
-- | Fills a range in a buffer with the specified octet.
107
- fill :: Octet -> Offset -> Offset -> b -> e Unit
107
+ fill :: Octet -> Offset -> Offset -> buf -> m Unit
108
108
109
109
-- | A reference to a mutable buffer for use with `Effect`
110
110
foreign import data EffectBuffer :: Type
@@ -163,66 +163,66 @@ instance mutableBufferST :: MutableBuffer (STBuffer h) (ST h) where
163
163
copy = copyImpl
164
164
fill = fillImpl
165
165
166
- usingFromFrozen :: forall b e a . (Buffer -> a ) -> b -> e a
166
+ usingFromFrozen :: forall buf m a . (Buffer -> a ) -> buf -> m a
167
167
usingFromFrozen f buf = unsafeCoerce \_ -> f $ unsafeCoerce buf
168
168
169
- usingToFrozen :: forall b e a . (a -> Buffer ) -> a -> e b
169
+ usingToFrozen :: forall buf m a . (a -> Buffer ) -> a -> m buf
170
170
usingToFrozen f x = unsafeCoerce \_ -> unsafeCoerce $ f x
171
171
172
- createImpl :: forall b e . Int -> e b
172
+ createImpl :: forall buf m . Int -> m buf
173
173
createImpl = usingToFrozen Buffer .create
174
174
175
- foreign import copyAllImpl :: forall a b e . a -> e b
175
+ foreign import copyAllImpl :: forall a buf m . a -> m buf
176
176
177
- fromArrayImpl :: forall b e . Array Octet -> e b
177
+ fromArrayImpl :: forall buf m . Array Octet -> m buf
178
178
fromArrayImpl = usingToFrozen Buffer .fromArray
179
179
180
- fromStringImpl :: forall b e . String -> Encoding -> e b
180
+ fromStringImpl :: forall buf m . String -> Encoding -> m buf
181
181
fromStringImpl s = usingToFrozen $ Buffer .fromString s
182
182
183
- fromArrayBufferImpl :: forall b e . ArrayBuffer -> e b
183
+ fromArrayBufferImpl :: forall buf m . ArrayBuffer -> m buf
184
184
fromArrayBufferImpl = usingToFrozen Buffer .fromArrayBuffer
185
185
186
- toArrayBufferImpl :: forall b e . b -> e ArrayBuffer
186
+ toArrayBufferImpl :: forall buf m . buf -> m ArrayBuffer
187
187
toArrayBufferImpl = usingFromFrozen Buffer .toArrayBuffer
188
188
189
- readImpl :: forall b e . BufferValueType -> Offset -> b -> e Int
189
+ readImpl :: forall buf m . BufferValueType -> Offset -> buf -> m Int
190
190
readImpl t o = usingFromFrozen $ Buffer .read t o
191
191
192
- readStringImpl :: forall b e . Encoding -> Offset -> Offset -> b -> e String
193
- readStringImpl e o o' = usingFromFrozen $ Buffer .readString e o o'
192
+ readStringImpl :: forall buf m . Encoding -> Offset -> Offset -> buf -> m String
193
+ readStringImpl m o o' = usingFromFrozen $ Buffer .readString m o o'
194
194
195
- toStringImpl :: forall b e . Encoding -> b -> e String
196
- toStringImpl e = usingFromFrozen $ Buffer .toString e
195
+ toStringImpl :: forall buf m . Encoding -> buf -> m String
196
+ toStringImpl m = usingFromFrozen $ Buffer .toString m
197
197
198
- writeImpl :: forall b e . BufferValueType -> Int -> Offset -> b -> e Unit
198
+ writeImpl :: forall buf m . BufferValueType -> Int -> Offset -> buf -> m Unit
199
199
writeImpl = writeInternal <<< show
200
200
201
- foreign import writeInternal :: forall b e . String -> Int -> Offset -> b -> e Unit
201
+ foreign import writeInternal :: forall buf m . String -> Int -> Offset -> buf -> m Unit
202
202
203
- writeStringImpl :: forall b e . Encoding -> Offset -> Int -> String -> b -> e Int
203
+ writeStringImpl :: forall buf m . Encoding -> Offset -> Int -> String -> buf -> m Int
204
204
writeStringImpl = writeStringInternal <<< encodingToNode
205
205
206
206
foreign import writeStringInternal ::
207
- forall b e . String -> Offset -> Int -> String -> b -> e Int
207
+ forall buf m . String -> Offset -> Int -> String -> buf -> m Int
208
208
209
- toArrayImpl :: forall b e . b -> e (Array Octet )
209
+ toArrayImpl :: forall buf m . buf -> m (Array Octet )
210
210
toArrayImpl = usingFromFrozen Buffer .toArray
211
211
212
- getAtOffsetImpl :: forall b e . Offset -> b -> e (Maybe Octet )
212
+ getAtOffsetImpl :: forall buf m . Offset -> buf -> m (Maybe Octet )
213
213
getAtOffsetImpl o = usingFromFrozen $ Buffer .getAtOffset o
214
214
215
- foreign import setAtOffsetImpl :: forall b e . Octet -> Offset -> b -> e Unit
215
+ foreign import setAtOffsetImpl :: forall buf m . Octet -> Offset -> buf -> m Unit
216
216
217
- sizeImpl :: forall b e . b -> e Int
217
+ sizeImpl :: forall buf m . buf -> m Int
218
218
sizeImpl = usingFromFrozen Buffer .size
219
219
220
- concatImpl :: forall b e . Array b -> e b
220
+ concatImpl :: forall buf m . Array buf -> m buf
221
221
concatImpl arrs = unsafeCoerce \_ -> Buffer .concat (unsafeCoerce arrs)
222
222
223
- concatImpl' :: forall b e . Array b -> Int -> e b
223
+ concatImpl' :: forall buf m . Array buf -> Int -> m buf
224
224
concatImpl' arrs n = unsafeCoerce \_ -> Buffer .concat' (unsafeCoerce arrs) n
225
225
226
- foreign import copyImpl :: forall b e . Offset -> Offset -> b -> Offset -> b -> e Int
226
+ foreign import copyImpl :: forall buf m . Offset -> Offset -> buf -> Offset -> buf -> m Int
227
227
228
- foreign import fillImpl :: forall b e . Octet -> Offset -> Offset -> b -> e Unit
228
+ foreign import fillImpl :: forall buf m . Octet -> Offset -> Offset -> buf -> m Unit
0 commit comments