1
1
module Data.ArrayBuffer.Typed
2
- ( buffer
2
+ ( polyFill
3
+ , buffer
3
4
, byteOffset
4
5
, byteLength
6
+ , AProxy (..)
5
7
, class Bytes
6
8
, bytesPer
7
9
, length
@@ -15,17 +17,20 @@ module Data.ArrayBuffer.Typed
15
17
16
18
import Prelude
17
19
import Effect (Effect )
20
+ import Effect.Uncurried (EffectFn2 , runEffectFn2 )
18
21
import Data.ArrayBuffer.Types
19
- ( ArrayView , ByteOffset
22
+ ( ArrayView , kind ArrayViewType , ArrayBuffer , ByteOffset , ByteLength
20
23
, Float64Array , Float32Array
21
24
, Uint8ClampedArray , Uint32Array , Uint16Array , Uint8Array , Int32Array , Int16Array , Int8Array
22
25
, Float64 , Float32
23
26
, Uint8Clamped , Uint32 , Uint16 , Uint8 , Int32 , Int16 , Int8 )
24
27
import Data.Function.Uncurried (Fn2 , Fn3 , runFn2 , runFn3 )
25
28
import Data.Maybe (Maybe (..))
26
- import Type.Proxy (Proxy (..))
27
29
28
30
31
+ -- | Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill
32
+ foreign import polyFill :: Effect Unit
33
+
29
34
-- | `ArrayBuffer` being mapped by the typed array.
30
35
foreign import buffer :: forall a . ArrayView a -> ArrayBuffer
31
36
@@ -37,23 +42,25 @@ foreign import byteLength :: forall a. ArrayView a -> ByteLength
37
42
38
43
foreign import lengthImpl :: forall a . ArrayView a -> Int
39
44
40
- class Bytes a where
41
- bytesPer :: Proxy a -> Int
45
+ data AProxy (a :: ArrayViewType ) = AProxy
46
+
47
+ class Bytes (a :: ArrayViewType ) where
48
+ bytesPer :: AProxy a -> Int
42
49
43
50
instance bytesUint8Clamped :: Bytes Uint8Clamped where
44
- bytesPer Proxy = 1
51
+ bytesPer AProxy = 1
45
52
instance bytesUint32 :: Bytes Uint32 where
46
- bytesPer Proxy = 4
53
+ bytesPer AProxy = 4
47
54
instance bytesUint16 :: Bytes Uint16 where
48
- bytesPer Proxy = 2
55
+ bytesPer AProxy = 2
49
56
instance bytesUint8 :: Bytes Uint8 where
50
- bytesPer Proxy = 1
57
+ bytesPer AProxy = 1
51
58
instance bytesInt32 :: Bytes Int32 where
52
- bytesPer Proxy = 4
59
+ bytesPer AProxy = 4
53
60
instance bytesInt16 :: Bytes Int16 where
54
- bytesPer Proxy = 2
61
+ bytesPer AProxy = 2
55
62
instance bytesInt8 :: Bytes Int8 where
56
- bytesPer Proxy = 1
63
+ bytesPer AProxy = 1
57
64
58
65
length :: forall a . Bytes a => ArrayView a -> Int
59
66
length = lengthImpl
0 commit comments