Skip to content

Commit 22e4db7

Browse files
committed
Fix bounds and instances for UInt
1 parent 5e737ae commit 22e4db7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lsp-types/lsp-types.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ library
8787
, mtl
8888
, network-uri
8989
, mod
90-
, semirings
9190
, rope-utf16-splay >= 0.3.1.0
9291
, scientific
9392
, some

lsp-types/src/Language/LSP/Types/Common.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,32 @@ module Language.LSP.Types.Common (
1818
import Control.Applicative
1919
import Control.DeepSeq
2020
import Data.Aeson
21-
import Data.Coerce (coerce)
22-
import Data.Euclidean as E
2321
import Data.Int (Int32)
2422
import Data.Mod.Word
2523
import Text.Read (Read(readPrec))
2624
import GHC.Generics hiding (UInt)
25+
import GHC.TypeNats hiding (Mod)
26+
import Data.Bifunctor (bimap)
2727

2828
-- | The "uinteger" type in the LSP spec.
2929
--
3030
-- 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)
3333
deriving stock (Generic)
3434
deriving anyclass (NFData)
3535

36+
instance Show UInt where
37+
show (UInt u) = show $ unMod u
38+
3639
instance Read UInt where
3740
readPrec = fromInteger <$> readPrec
3841

3942
instance Real UInt where
4043
toRational (UInt u) = toRational $ unMod u
4144

4245
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)
4447
toInteger (UInt u) = toInteger $ unMod u
4548

4649
instance ToJSON UInt where

0 commit comments

Comments
 (0)