@@ -24,29 +24,28 @@ import Data.Coerce
24
24
import Data.Functor.Classes (showsUnaryWith )
25
25
import Data.Nat
26
26
import Data.Word
27
- import GHC.TypeLits
28
27
import Numeric (showIntAtBase )
29
28
30
29
type role Index representational
31
30
32
31
newtype Index (i :: N ) = Index { getIndex :: Word32 }
33
32
deriving (Eq , Ord )
34
33
35
- instance KnownNat ( Place i ) => Bounded (Index i ) where
34
+ instance Place i => Bounded (Index i ) where
36
35
minBound = Index 0
37
36
{-# INLINABLE minBound #-}
38
37
maxBound = let i = Index (bit (place i) - 1 ) in i
39
38
{-# INLINABLE maxBound #-}
40
39
41
- instance KnownNat ( Place i ) => Enum (Index i ) where
40
+ instance Place i => Enum (Index i ) where
42
41
toEnum i | i' <- fromIntegral i
43
42
, i' <= getIndex (maxBound :: Index i ) = Index i'
44
43
| otherwise = error " Data.Bin.Index.Index.toEnum: bad argument"
45
44
{-# INLINABLE toEnum #-}
46
45
fromEnum = fromIntegral . getIndex
47
46
{-# INLINABLE fromEnum #-}
48
47
49
- instance KnownNat ( Place i ) => Bits (Index i ) where
48
+ instance Place i => Bits (Index i ) where
50
49
(.&.) = coerce ((.&.) :: Word32 -> Word32 -> Word32 )
51
50
{-# INLINABLE (.&.) #-}
52
51
(.|.) = coerce ((.|.) :: Word32 -> Word32 -> Word32 )
@@ -85,7 +84,7 @@ instance KnownNat (Place i) => Bits (Index i) where
85
84
in Index (shift (getIndex i) p' .|. shift (getIndex i) (- (bits - p'))) .&. maxBound
86
85
{-# INLINABLE rotate #-}
87
86
88
- instance KnownNat ( Place i ) => FiniteBits (Index i ) where
87
+ instance Place i => FiniteBits (Index i ) where
89
88
finiteBitSize = place
90
89
{-# INLINABLE finiteBitSize #-}
91
90
@@ -97,18 +96,18 @@ il :: Index 'Z
97
96
il = Index 0
98
97
{-# INLINABLE il #-}
99
98
100
- ib :: forall s . KnownNat ( Place s ) => Bit -> Index s -> Index ('S s )
99
+ ib :: Place s => Bit -> Index s -> Index ('S s )
101
100
ib B0 i = Index (getIndex i)
102
101
ib B1 i = Index (setBit (getIndex i) (place i))
103
102
{-# INLINABLE ib #-}
104
103
105
- i0 , i1 :: KnownNat ( Place s ) => Index s -> Index ('S s )
104
+ i0 , i1 :: Place s => Index s -> Index ('S s )
106
105
i0 = ib B0
107
106
{-# INLINABLE i0 #-}
108
107
i1 = ib B1
109
108
{-# INLINABLE i1 #-}
110
109
111
- decompose :: KnownNat ( Place i ) => Index ('S i ) -> (Bit , Index i )
110
+ decompose :: Place i => Index ('S i ) -> (Bit , Index i )
112
111
decompose i = (toBit (testBit (getIndex i) p), i')
113
112
where
114
113
p = place i'
0 commit comments