@@ -18,29 +18,32 @@ module Language.LSP.Types.Common (
18
18
import Control.Applicative
19
19
import Control.DeepSeq
20
20
import Data.Aeson
21
- import Data.Coerce (coerce )
22
- import Data.Euclidean as E
23
21
import Data.Int (Int32 )
24
22
import Data.Mod.Word
25
23
import Text.Read (Read (readPrec ))
26
24
import GHC.Generics hiding (UInt )
25
+ import GHC.TypeNats hiding (Mod )
26
+ import Data.Bifunctor (bimap )
27
27
28
28
-- | The "uinteger" type in the LSP spec.
29
29
--
30
30
-- Unusually, this is a **31**-bit unsigned integer, not a 32-bit one.
31
- newtype UInt = UInt (Mod 31 )
32
- deriving newtype (Num , Bounded , Enum , Eq , Ord , Show )
31
+ newtype UInt = UInt (Mod ( 2 ^ 31 ) )
32
+ deriving newtype (Num , Bounded , Enum , Eq , Ord )
33
33
deriving stock (Generic )
34
34
deriving anyclass (NFData )
35
35
36
+ instance Show UInt where
37
+ show (UInt u) = show $ unMod u
38
+
36
39
instance Read UInt where
37
40
readPrec = fromInteger <$> readPrec
38
41
39
42
instance Real UInt where
40
43
toRational (UInt u) = toRational $ unMod u
41
44
42
45
instance Integral UInt where
43
- quotRem (UInt x) (UInt y) = coerce $ E. quotRem x y
46
+ quotRem (UInt x) (UInt y) = bimap fromIntegral fromIntegral $ quotRem (unMod x) (unMod y)
44
47
toInteger (UInt u) = toInteger $ unMod u
45
48
46
49
instance ToJSON UInt where
0 commit comments