Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bounded instances for int types #109

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/Data/Int/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ instance Integral Int8 where
toInteger = _intToInteger . unI8

instance Bounded Int8 where
minBound = I8 0x80
maxBound = I8 0x7f
minBound = i8 0x80
maxBound = i8 0x7f

instance Real Int8 where
toRational = _integerToRational . _intToInteger . unI8
Expand Down Expand Up @@ -150,8 +150,8 @@ instance Integral Int16 where
toInteger = _intToInteger . unI16

instance Bounded Int16 where
minBound = I16 0x8000
maxBound = I16 0x7fff
minBound = i16 0x8000
maxBound = i16 0x7fff

instance Real Int16 where
toRational = _integerToRational . _intToInteger . unI16
Expand Down Expand Up @@ -246,8 +246,8 @@ instance Integral Int32 where
toInteger = _intToInteger . unI32

instance Bounded Int32 where
minBound = I32 0x80000000
maxBound = I32 0x7fffffff
minBound = i32 0x80000000
maxBound = i32 0x7fffffff

instance Real Int32 where
toRational = _integerToRational . _intToInteger . unI32
Expand Down Expand Up @@ -341,8 +341,8 @@ instance Integral Int64 where
toInteger = _intToInteger . unI64

instance Bounded Int64 where
minBound = I64 0x8000000000000000
maxBound = I64 0x7fffffffffffffff
minBound = i64 0x8000000000000000
maxBound = i64 0x7fffffffffffffff

instance Real Int64 where
toRational = _integerToRational . _intToInteger . unI64
Expand Down
16 changes: 8 additions & 8 deletions lib/Data/Word.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ instance Integral Word8 where
toInteger = _wordToInteger . unW8

instance Bounded Word8 where
minBound = W8 0
maxBound = W8 0xff
minBound = w8 0
maxBound = w8 0xff

instance Real Word8 where
toRational = _integerToRational . _wordToInteger . unW8
Expand Down Expand Up @@ -239,8 +239,8 @@ instance Integral Word16 where
toInteger = _wordToInteger . unW16

instance Bounded Word16 where
minBound = W16 0
maxBound = W16 0xffff
minBound = w16 0
maxBound = w16 0xffff

instance Real Word16 where
toRational = _integerToRational . _wordToInteger . unW16
Expand Down Expand Up @@ -336,8 +336,8 @@ instance Integral Word32 where
toInteger = _wordToInteger . unW32

instance Bounded Word32 where
minBound = W32 0
maxBound = W32 0xffffffff
minBound = w32 0
maxBound = w32 0xffffffff

instance Real Word32 where
toRational = _integerToRational . _wordToInteger . unW32
Expand Down Expand Up @@ -434,8 +434,8 @@ instance Integral Word64 where
toInteger = _wordToInteger . unW64

instance Bounded Word64 where
minBound = W64 0
maxBound = W64 0xffffffffffffffff
minBound = w64 0
maxBound = w64 0xffffffffffffffff

instance Real Word64 where
toRational = _integerToRational . _wordToInteger . unW64
Expand Down
16 changes: 16 additions & 0 deletions tests/Bounded.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Bounded where

import Data.Int
import Data.Word

printBounds :: forall a. (Bounded a, Show a) => IO ()
printBounds = print (minBound @a, maxBound @a)

main :: IO ()
main = do
printBounds @Int8
printBounds @Int16
printBounds @Int32
printBounds @Word8
printBounds @Word16
printBounds @Word32
6 changes: 6 additions & 0 deletions tests/Bounded.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(-128,127)
(-32768,32767)
(-2147483648,2147483647)
(0,255)
(0,65535)
(0,4294967295)