Skip to content

Commit 5d1a7fd

Browse files
authored
Merge pull request #25 from athanclark/master
no need to distinguish DataView class and BinaryValue class
2 parents 1d1e709 + c99c202 commit 5d1a7fd

File tree

4 files changed

+27
-39
lines changed

4 files changed

+27
-39
lines changed

src/Data/ArrayBuffer/DataView.purs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module Data.ArrayBuffer.DataView
77
, buffer
88
, byteLength
99
, byteOffset
10-
, class DataView
11-
, class ShowArrayViewType
1210
, get
1311
, getBE
1412
, getFloat32be
@@ -48,8 +46,8 @@ module Data.ArrayBuffer.DataView
4846
, whole
4947
) where
5048

51-
import Data.ArrayBuffer.Types (ArrayBuffer, ByteLength, ByteOffset, DataView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped, kind ArrayViewType)
52-
import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue)
49+
import Data.ArrayBuffer.Types (ArrayBuffer, ByteLength, ByteOffset, DataView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, kind ArrayViewType)
50+
import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue, class ShowArrayViewType)
5351
import Data.Float32 (Float32) as F
5452
import Data.Maybe (Maybe)
5553
import Data.Nullable (Nullable, toMaybe)
@@ -96,29 +94,6 @@ instance eqEndian :: Eq Endian where
9694
eq BE BE = true
9795
eq _ _ = false
9896

99-
class BinaryValue a t <= DataView (a :: ArrayViewType) t | a -> t
100-
101-
instance dataViewUint8Clamped :: DataView Uint8Clamped UInt
102-
instance dataViewUint32 :: DataView Uint32 UInt
103-
instance dataViewUint16 :: DataView Uint16 UInt
104-
instance dataViewUint8 :: DataView Uint8 UInt
105-
instance dataViewInt32 :: DataView Int32 Int
106-
instance dataViewInt16 :: DataView Int16 Int
107-
instance dataViewInt8 :: DataView Int8 Int
108-
instance dataViewFloat32 :: DataView Float32 F.Float32
109-
instance dataViewFloat64 :: DataView Float64 Number
110-
111-
112-
class ShowArrayViewType (a :: ArrayViewType) (name :: Symbol) | a -> name
113-
instance showArrayViewTypeUint8Clamped :: ShowArrayViewType Uint8Clamped "Uint8Clamped"
114-
instance showArrayViewTypeViewUint32 :: ShowArrayViewType Uint32 "Uint32"
115-
instance showArrayViewTypeViewUint16 :: ShowArrayViewType Uint16 "Uint16"
116-
instance showArrayViewTypeViewUint8 :: ShowArrayViewType Uint8 "Uint8"
117-
instance showArrayViewTypeViewInt32 :: ShowArrayViewType Int32 "Int32"
118-
instance showArrayViewTypeViewInt16 :: ShowArrayViewType Int16 "Int16"
119-
instance showArrayViewTypeViewInt8 :: ShowArrayViewType Int8 "Int8"
120-
instance showArrayViewTypeViewFloat32 :: ShowArrayViewType Float32 "Float32"
121-
instance showArrayViewTypeViewFloat64 :: ShowArrayViewType Float64 "Float64"
12297

12398
getter :: forall t.
12499
{ functionName :: String
@@ -141,7 +116,7 @@ foreign import getterImpl :: forall t
141116

142117

143118
get :: forall a name t b
144-
. DataView a t
119+
. BinaryValue a t
145120
=> BytesPerValue a b
146121
=> ShowArrayViewType a name
147122
=> IsSymbol name
@@ -157,7 +132,7 @@ get endian prx =
157132
}
158133

159134
getBE :: forall a name t b
160-
. DataView a t
135+
. BinaryValue a t
161136
=> BytesPerValue a b
162137
=> ShowArrayViewType a name
163138
=> IsSymbol name
@@ -166,7 +141,7 @@ getBE :: forall a name t b
166141
getBE = get BE
167142

168143
getLE :: forall a name t b
169-
. DataView a t
144+
. BinaryValue a t
170145
=> BytesPerValue a b
171146
=> ShowArrayViewType a name
172147
=> IsSymbol name
@@ -188,7 +163,7 @@ foreign import setterImpl :: forall t
188163

189164

190165
set :: forall a name t b
191-
. DataView a t
166+
. BinaryValue a t
192167
=> BytesPerValue a b
193168
=> ShowArrayViewType a name
194169
=> IsSymbol name
@@ -262,7 +237,7 @@ getFloat64le = getLE (AProxy :: AProxy Float64)
262237

263238
-- | Store big-endian value at a certain index in a `DataView`.
264239
setBE :: forall a name t b
265-
. DataView a t
240+
. BinaryValue a t
266241
=> BytesPerValue a b
267242
=> ShowArrayViewType a name
268243
=> IsSymbol name
@@ -272,7 +247,7 @@ setBE = set BE
272247

273248
-- | Store little-endian value at a certain index in a `DataView`.
274249
setLE :: forall a name t b
275-
. DataView a t
250+
. BinaryValue a t
276251
=> BytesPerValue a b
277252
=> ShowArrayViewType a name
278253
=> IsSymbol name

src/Data/ArrayBuffer/DataView/Gen.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import Control.Monad.Gen (suchThat)
66
import Control.Monad.Gen.Class (class MonadGen, chooseInt)
77
import Control.Monad.Rec.Class (class MonadRec)
88
import Data.ArrayBuffer.ArrayBuffer.Gen (genArrayBuffer)
9-
import Data.ArrayBuffer.DataView (whole, byteLength, class DataView)
9+
import Data.ArrayBuffer.DataView (whole, byteLength)
1010
import Data.ArrayBuffer.Types (DataView, ByteOffset, kind ArrayViewType)
11-
import Data.ArrayBuffer.ValueMapping (class BytesPerValue)
11+
import Data.ArrayBuffer.ValueMapping (class BytesPerValue, class BinaryValue)
1212
import Data.Maybe (Maybe(Just))
1313
import Data.Typelevel.Num (class Nat, toInt')
1414
import Data.Unfoldable (replicateA)
@@ -34,7 +34,7 @@ genWithOffsetAndValue :: forall m n a b t
3434
=> MonadRec m
3535
=> Nat n
3636
=> BytesPerValue a b
37-
=> DataView a t
37+
=> BinaryValue a t
3838
=> Nat b
3939
=> m DataView -- ^ Assumes generated length is at least the minimum length of one value
4040
-> m t

src/Data/ArrayBuffer/ValueMapping.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,16 @@ instance binaryValueInt16 :: BinaryValue Int16 Int
3535
instance binaryValueInt8 :: BinaryValue Int8 Int
3636
instance binaryValueFloat32 :: BinaryValue Float32 F.Float32
3737
instance binaryValueFloat64 :: BinaryValue Float64 Number
38+
39+
40+
41+
class ShowArrayViewType (a :: ArrayViewType) (name :: Symbol) | a -> name
42+
instance showArrayViewTypeUint8Clamped :: ShowArrayViewType Uint8Clamped "Uint8Clamped"
43+
instance showArrayViewTypeViewUint32 :: ShowArrayViewType Uint32 "Uint32"
44+
instance showArrayViewTypeViewUint16 :: ShowArrayViewType Uint16 "Uint16"
45+
instance showArrayViewTypeViewUint8 :: ShowArrayViewType Uint8 "Uint8"
46+
instance showArrayViewTypeViewInt32 :: ShowArrayViewType Int32 "Int32"
47+
instance showArrayViewTypeViewInt16 :: ShowArrayViewType Int16 "Int16"
48+
instance showArrayViewTypeViewInt8 :: ShowArrayViewType Int8 "Int8"
49+
instance showArrayViewTypeViewFloat32 :: ShowArrayViewType Float32 "Float32"
50+
instance showArrayViewTypeViewFloat64 :: ShowArrayViewType Float64 "Float64"

test/Properties/DataView.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Data.ArrayBuffer.DataView as DV
77
import Data.ArrayBuffer.DataView.Gen (genDataView, genWithOffsetAndValue, WithOffsetAndValue(..))
88
import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genUint16, genUint32, genUint8)
99
import Data.ArrayBuffer.Types (Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8)
10-
import Data.ArrayBuffer.ValueMapping (class BytesPerValue)
10+
import Data.ArrayBuffer.ValueMapping (class BytesPerValue, class ShowArrayViewType, class BinaryValue)
1111
import Data.Maybe (Maybe(..))
1212
import Data.Typelevel.Num (class Nat, D1, D2, D4, D8)
1313
import Data.UInt (UInt)
@@ -37,10 +37,10 @@ type TestableViewF a name b n t q =
3737
=> Ord t
3838
=> Semiring t
3939
=> BytesPerValue a b
40-
=> DV.ShowArrayViewType a name
40+
=> BinaryValue a t
41+
=> ShowArrayViewType a name
4142
=> IsSymbol name
4243
=> Nat b
43-
=> DV.DataView a t
4444
=> WithOffsetAndValue n a t
4545
-> q
4646

0 commit comments

Comments
 (0)