[Git][ghc/ghc][wip/T26961] Add Infinity/NegInfinity/NaN pattern synonyms (#26961)
Brandon Chinn pushed to branch wip/T26961 at Glasgow Haskell Compiler / GHC Commits: 2c7d6e17 by Brandon Chinn at 2026-02-25T08:53:33-08:00 Add Infinity/NegInfinity/NaN pattern synonyms (#26961) - - - - - 2 changed files: - libraries/base/changelog.md - libraries/base/src/Data/RealFloat.hs Changes: ===================================== libraries/base/changelog.md ===================================== @@ -10,6 +10,7 @@ * 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)) * Ensure that `rationalToFloat` and `rationalToDouble` always inline in the end. ([CLC proposal #356](https://github.com/haskell/core-libraries-committee/issues/356)) * Add new `Data.RealFloat` module re-exporting `RealFloat` operations from `GHC.Float` + * Add `Infinity`, `NegInfinity`, and `NaN` pattern synonyms to `Data.RealFloat` * Modify the implementation of `Data.List.sortOn` to use `(>)` instead of `compare`. ([CLC proposal #332](https://github.com/haskell/core-libraries-committee/issues/332)) * Add `thenA` and `thenM`. ([CLC proposal #351](https://github.com/haskell/core-libraries-committee/issues/351)) * 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,4 +1,6 @@ +{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE Safe #-} +{-# LANGUAGE ViewPatterns #-} -- | -- @@ -26,6 +28,23 @@ module Data.RealFloat ( integerToBinaryFloat', fromRat, fromRat', + + -- * Infinity + NaN + pattern Infinity, + pattern NegInfinity, + pattern NaN, ) where import GHC.Internal.Float + +pattern Infinity :: (RealFloat a) => a +pattern Infinity <- ((\x -> isInfinite x && x > 0) -> True) where Infinity = 1/0 + +-- | Negative infinity +-- +-- Only necessary for pattern matching; expressions could also use @-Infinity@. +pattern NegInfinity :: (RealFloat a) => a +pattern NegInfinity <- ((\x -> isInfinite x && x < 0) -> True) where NegInfinity = -1/0 + +pattern NaN :: (RealFloat a) => a +pattern NaN <- (isNaN -> True) where NaN = 0/0 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2c7d6e17a46266678ba71662a56b5cd6... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2c7d6e17a46266678ba71662a56b5cd6... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Brandon Chinn (@brandonchinn178)