Brandon Chinn pushed to branch wip/T26961 at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • libraries/base/changelog.md
    ... ... @@ -10,6 +10,7 @@
    10 10
       * Fix issues with toRational for types capable to represent infinite and not-a-number values ([CLC proposal #338](https://github.com/haskell/core-libraries-committee/issues/338))
    
    11 11
       * Ensure that `rationalToFloat` and `rationalToDouble` always inline in the end. ([CLC proposal #356](https://github.com/haskell/core-libraries-committee/issues/356))
    
    12 12
       * Add new `Data.RealFloat` module re-exporting `RealFloat` operations from `GHC.Float`
    
    13
    +  * Add `Infinity`, `NegInfinity`, and `NaN` pattern synonyms to `Data.RealFloat`
    
    13 14
       * Modify the implementation of `Data.List.sortOn` to use `(>)` instead of `compare`. ([CLC proposal #332](https://github.com/haskell/core-libraries-committee/issues/332))
    
    14 15
       * Add `thenA` and `thenM`. ([CLC proposal #351](https://github.com/haskell/core-libraries-committee/issues/351))
    
    15 16
       * Fix bug where `naturalAndNot` was incorrectly truncating results ([CLC proposal #350](github.com/haskell/core-libraries-committee/issues/350))
    

  • libraries/base/src/Data/RealFloat.hs
    1
    +{-# LANGUAGE PatternSynonyms #-}
    
    1 2
     {-# LANGUAGE Safe #-}
    
    3
    +{-# LANGUAGE ViewPatterns #-}
    
    2 4
     
    
    3 5
     -- |
    
    4 6
     --
    
    ... ... @@ -26,6 +28,23 @@ module Data.RealFloat (
    26 28
       integerToBinaryFloat',
    
    27 29
       fromRat,
    
    28 30
       fromRat',
    
    31
    +
    
    32
    +  -- * Infinity + NaN
    
    33
    +  pattern Infinity,
    
    34
    +  pattern NegInfinity,
    
    35
    +  pattern NaN,
    
    29 36
     ) where
    
    30 37
     
    
    31 38
     import GHC.Internal.Float
    
    39
    +
    
    40
    +pattern Infinity :: (RealFloat a) => a
    
    41
    +pattern Infinity <- ((\x -> isInfinite x && x > 0) -> True) where Infinity = 1/0
    
    42
    +
    
    43
    +-- | Negative infinity
    
    44
    +--
    
    45
    +-- Only necessary for pattern matching; expressions could also use @-Infinity@.
    
    46
    +pattern NegInfinity :: (RealFloat a) => a
    
    47
    +pattern NegInfinity <- ((\x -> isInfinite x && x < 0) -> True) where NegInfinity = -1/0
    
    48
    +
    
    49
    +pattern NaN :: (RealFloat a) => a
    
    50
    +pattern NaN <- (isNaN -> True) where NaN = 0/0