Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

6 changed files:

Changes:

  • libraries/base/base.cabal.in
    ... ... @@ -117,6 +117,7 @@ Library
    117 117
             , Data.Monoid
    
    118 118
             , Data.Ord
    
    119 119
             , Data.Proxy
    
    120
    +        , Data.RealFloat
    
    120 121
             , Data.STRef
    
    121 122
             , Data.STRef.Strict
    
    122 123
             , Data.String
    

  • libraries/base/changelog.md
    ... ... @@ -9,6 +9,8 @@
    9 9
       * Introduce `Data.Double` and `Data.Float` modules. ([CLC proposal #378](https://github.com/haskell/core-libraries-committee/issues/378))
    
    10 10
       * Change `Generically a`'s `Monoid` definition to require a `Semigroup` constraint, and define its `mconcat` using `(<>)` from that constraint. ([CLC proposal #413](https://github.com/haskell/core-libraries-committee/issues/413))
    
    11 11
       * Add `withEmptyCallStack` to `GHC.Stack`. ([CLC proposal #428](https://github.com/haskell/core-libraries-committee/issues/428))
    
    12
    +  * Add new `Data.RealFloat` module re-exporting `RealFloat` from `GHC.Float` ([CLC proposal #394](https://github.com/haskell/core-libraries-committee/issues/394))
    
    13
    +  * Add `Infinity`, `NegInfinity`, and `NaN` pattern synonyms to `Data.RealFloat` ([CLC proposal #394](https://github.com/haskell/core-libraries-committee/issues/394))
    
    12 14
     
    
    13 15
     ## 4.23.0.0 *TBA*
    
    14 16
       * Add `System.IO.hGetNewlineMode`. ([CLC proposal #370](https://github.com/haskell/core-libraries-committee/issues/370))
    

  • libraries/base/src/Data/RealFloat.hs
    1
    +{-# LANGUAGE CPP #-}
    
    2
    +{-# LANGUAGE PatternSynonyms #-}
    
    3
    +{-# LANGUAGE Safe #-}
    
    4
    +{-# LANGUAGE ViewPatterns #-}
    
    5
    +
    
    6
    +-- |
    
    7
    +--
    
    8
    +-- Module      :  Data.RealFloat
    
    9
    +-- Copyright   :  (c) The University of Glasgow 2026
    
    10
    +-- License     :  BSD-style (see the file libraries/base/LICENSE)
    
    11
    +--
    
    12
    +-- Maintainer  :  libraries@haskell.org
    
    13
    +-- Stability   :  stable
    
    14
    +-- Portability :  portable
    
    15
    +--
    
    16
    +
    
    17
    +module Data.RealFloat (
    
    18
    +  RealFloat (..),
    
    19
    +
    
    20
    +  -- * Infinity + NaN
    
    21
    +  pattern Infinity,
    
    22
    +  pattern NegInfinity,
    
    23
    +  pattern NaN,
    
    24
    +) where
    
    25
    +
    
    26
    +import Data.Bool (Bool (..), (&&))
    
    27
    +import GHC.Internal.Data.Ord ((<), (>))
    
    28
    +import GHC.Internal.Float (RealFloat (..))
    
    29
    +import GHC.Internal.Real ((/))
    
    30
    +#if __GLASGOW_HASKELL__ >= 1001
    
    31
    +import qualified GHC.Essentials as Rebindable
    
    32
    +#endif
    
    33
    +
    
    34
    +pattern Infinity :: (RealFloat a) => a
    
    35
    +pattern Infinity <- ((\x -> isInfinite x && x > 0) -> True) where Infinity = 1/0
    
    36
    +
    
    37
    +-- | Negative infinity
    
    38
    +--
    
    39
    +-- Provided for convenience. Could also use the following instead:
    
    40
    +--   * Pattern matching: @(negate -> Infinity)@
    
    41
    +--   * Expressions: @-Infinity@
    
    42
    +pattern NegInfinity :: (RealFloat a) => a
    
    43
    +pattern NegInfinity <- ((\x -> isInfinite x && x < 0) -> True) where NegInfinity = -1/0
    
    44
    +
    
    45
    +-- | A pattern synonym for NaN values.
    
    46
    +--
    
    47
    +-- Note: Per IEEE 754, NaN is never equal to itself, thus these two snippets
    
    48
    +-- have different behavior:
    
    49
    +--
    
    50
    +-- @
    
    51
    +-- -- foo1 NaN == "a"
    
    52
    +-- foo1 NaN = "a"
    
    53
    +-- foo1 _ = "b"
    
    54
    +--
    
    55
    +-- -- foo2 NaN == "b"
    
    56
    +-- foo2 x = if x == NaN then "a" else "b"
    
    57
    +-- @
    
    58
    +pattern NaN :: (RealFloat a) => a
    
    59
    +pattern NaN <- (isNaN -> True) where NaN = 0/0

  • testsuite/tests/interface-stability/base-exports.stdout
    No preview for this file type
  • testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
    No preview for this file type
  • testsuite/tests/interface-stability/base-exports.stdout-mingw32
    No preview for this file type