mirror of
https://github.com/tfausak/witch.git
synced 2024-11-23 00:06:27 +03:00
Fix broken conversions into naturals
This commit is contained in:
parent
566ff323fd
commit
d86ffe4f5f
@ -251,7 +251,12 @@ instance TryFrom.TryFrom Int.Int64 Word where
|
|||||||
|
|
||||||
-- | Uses 'fromIntegral' when the input is not negative.
|
-- | Uses 'fromIntegral' when the input is not negative.
|
||||||
instance TryFrom.TryFrom Int.Int64 Natural.Natural where
|
instance TryFrom.TryFrom Int.Int64 Natural.Natural where
|
||||||
tryFrom = Utility.eitherTryFrom fromNonNegativeIntegral
|
-- This should use @eitherTryFrom fromNonNegativeIntegral@, but that causes
|
||||||
|
-- a bug in GHC 9.0.1.
|
||||||
|
-- https://mail.haskell.org/pipermail/haskell-cafe/2021-March/133540.html
|
||||||
|
tryFrom s = case TryFrom.tryFrom (From.from s :: Integer) of
|
||||||
|
Left (TryFromException.TryFromException _ e) -> Left $ TryFromException.TryFromException s e
|
||||||
|
Right t -> Right t
|
||||||
|
|
||||||
-- | Uses 'fromIntegral' when the input is between -16,777,215 and 16,777,215
|
-- | Uses 'fromIntegral' when the input is between -16,777,215 and 16,777,215
|
||||||
-- inclusive.
|
-- inclusive.
|
||||||
@ -590,7 +595,9 @@ instance TryFrom.TryFrom Word.Word64 Word where
|
|||||||
|
|
||||||
-- | Uses 'fromIntegral'.
|
-- | Uses 'fromIntegral'.
|
||||||
instance From.From Word.Word64 Natural.Natural where
|
instance From.From Word.Word64 Natural.Natural where
|
||||||
from = fromIntegral
|
-- This should use @fromIntegral@, but that causes a bug in GHC 9.0.1.
|
||||||
|
-- https://mail.haskell.org/pipermail/haskell-cafe/2021-March/133540.html
|
||||||
|
from s = Utility.unsafeFrom (From.from s :: Integer)
|
||||||
|
|
||||||
-- | Uses 'Bits.toIntegralSized'.
|
-- | Uses 'Bits.toIntegralSized'.
|
||||||
instance TryFrom.TryFrom Word.Word64 Int.Int8 where
|
instance TryFrom.TryFrom Word.Word64 Int.Int8 where
|
||||||
|
Loading…
Reference in New Issue
Block a user