Teo Camarasu pushed to branch wip/T26865 at Glasgow Haskell Compiler / GHC Commits: 905e07ec by Teo Camarasu at 2026-01-31T13:57:07+00:00 ghc-internal: Move GHC.Internal.Data.Bool to base This is a tiny module that only defines bool :: Bool -> a -> a -> a. We can just move this to base and delete it from ghc-internal. If we want this functionality there we can just use a case statement or if-then expression. Resolves 26865 - - - - - 19 changed files: - libraries/base/src/Data/Bool.hs - libraries/base/src/Data/List.hs - libraries/base/src/Data/List/NubOrdSet.hs - libraries/ghc-internal/ghc-internal.cabal.in - − libraries/ghc-internal/src/GHC/Internal/Data/Bool.hs - libraries/ghc-internal/src/GHC/Internal/Data/Foldable.hs - libraries/ghc-internal/src/GHC/Internal/Data/Function.hs - libraries/ghc-internal/src/GHC/Internal/Data/Type/Bool.hs - libraries/ghc-internal/src/GHC/Internal/Data/Type/Ord.hs - libraries/ghc-internal/src/GHC/Internal/Data/Version.hs - libraries/ghc-internal/src/GHC/Internal/IO/FD.hs - libraries/ghc-internal/src/GHC/Internal/JS/Prim.hs - libraries/ghc-internal/src/GHC/Internal/System/IO/OS.hs - libraries/ghc-internal/src/GHC/Internal/TH/Lift.hs - libraries/ghc-internal/src/GHC/Internal/TypeError.hs - testsuite/tests/interface-stability/base-exports.stdout - testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs - testsuite/tests/interface-stability/base-exports.stdout-mingw32 - testsuite/tests/interface-stability/base-exports.stdout-ws-32 Changes: ===================================== libraries/base/src/Data/Bool.hs ===================================== @@ -1,4 +1,4 @@ -{-# LANGUAGE Safe #-} +{-# LANGUAGE Trustworthy #-} -- | -- @@ -24,4 +24,39 @@ module Data.Bool bool ) where -import GHC.Internal.Data.Bool \ No newline at end of file +import GHC.Internal.Base + +-- $setup +-- >>> import Prelude + +-- | Case analysis for the 'Bool' type. @'bool' f t p@ evaluates to @f@ +-- when @p@ is 'False', and evaluates to @t@ when @p@ is 'True'. +-- +-- This is equivalent to @if p then t else f@; that is, one can +-- think of it as an if-then-else construct with its arguments +-- reordered. +-- +-- @since base-4.7.0.0 +-- +-- ==== __Examples__ +-- +-- Basic usage: +-- +-- >>> bool "foo" "bar" True +-- "bar" +-- >>> bool "foo" "bar" False +-- "foo" +-- +-- Confirm that @'bool' f t p@ and @if p then t else f@ are +-- equivalent: +-- +-- >>> let p = True; f = "bar"; t = "foo" +-- >>> bool f t p == if p then t else f +-- True +-- >>> let p = False +-- >>> bool f t p == if p then t else f +-- True +-- +bool :: a -> a -> Bool -> a +bool f _ False = f +bool _ t True = t ===================================== libraries/base/src/Data/List.hs ===================================== @@ -1,4 +1,4 @@ -{-# LANGUAGE Safe #-} +{-# LANGUAGE Trustworthy #-} -- | -- @@ -184,7 +184,7 @@ module Data.List genericReplicate ) where -import GHC.Internal.Data.Bool (otherwise) +import GHC.Internal.Base (otherwise) import GHC.Internal.Data.Function (const) import GHC.Internal.Data.List import GHC.Internal.Data.List.NonEmpty (NonEmpty(..)) ===================================== libraries/base/src/Data/List/NubOrdSet.hs ===================================== @@ -11,7 +11,7 @@ module Data.List.NubOrdSet ( insert, ) where -import GHC.Internal.Data.Bool (Bool(..)) +import GHC.Internal.Base (Bool(..)) import GHC.Internal.Data.Function ((.)) import GHC.Internal.Data.Ord (Ordering(..)) ===================================== libraries/ghc-internal/ghc-internal.cabal.in ===================================== @@ -140,7 +140,6 @@ Library GHC.Internal.Control.Monad.ST.Imp GHC.Internal.Control.Monad.ST.Lazy.Imp GHC.Internal.Data.Bits - GHC.Internal.Data.Bool GHC.Internal.Data.Coerce GHC.Internal.Data.Data GHC.Internal.Data.Dynamic ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Bool.hs deleted ===================================== @@ -1,64 +0,0 @@ -{-# LANGUAGE Trustworthy #-} -{-# LANGUAGE NoImplicitPrelude #-} - ------------------------------------------------------------------------------ --- | --- Module : GHC.Internal.Data.Bool --- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/base/LICENSE) --- --- Maintainer : libraries@haskell.org --- Stability : stable --- Portability : portable --- --- The 'Bool' type and related functions. --- ------------------------------------------------------------------------------ - -module GHC.Internal.Data.Bool ( - -- * Booleans - Bool(..), - -- ** Operations - (&&), - (||), - not, - otherwise, - bool, - ) where - -import GHC.Internal.Base - --- $setup --- >>> import Prelude - --- | Case analysis for the 'Bool' type. @'bool' f t p@ evaluates to @f@ --- when @p@ is 'False', and evaluates to @t@ when @p@ is 'True'. --- --- This is equivalent to @if p then t else f@; that is, one can --- think of it as an if-then-else construct with its arguments --- reordered. --- --- @since base-4.7.0.0 --- --- ==== __Examples__ --- --- Basic usage: --- --- >>> bool "foo" "bar" True --- "bar" --- >>> bool "foo" "bar" False --- "foo" --- --- Confirm that @'bool' f t p@ and @if p then t else f@ are --- equivalent: --- --- >>> let p = True; f = "bar"; t = "foo" --- >>> bool f t p == if p then t else f --- True --- >>> let p = False --- >>> bool f t p == if p then t else f --- True --- -bool :: a -> a -> Bool -> a -bool f _ False = f -bool _ t True = t ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Foldable.hs ===================================== @@ -50,7 +50,6 @@ module GHC.Internal.Data.Foldable ( find ) where -import GHC.Internal.Data.Bool import GHC.Internal.Data.Either import GHC.Internal.Data.Eq import GHC.Internal.Data.Functor.Utils (Max(..), Min(..), (#.)) ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Function.hs ===================================== @@ -30,8 +30,7 @@ module GHC.Internal.Data.Function , applyWhen ) where -import GHC.Internal.Base ( TYPE, ($), (.), id, const, flip ) -import GHC.Internal.Data.Bool ( Bool(..) ) +import GHC.Internal.Base ( TYPE, Bool(..), ($), (.), id, const, flip ) infixl 0 `on` infixl 1 & @@ -171,7 +170,7 @@ x & f = f x -- | 'applyWhen' applies a function to a value if a condition is true, -- otherwise, it returns the value unchanged. -- --- It is equivalent to @'flip' ('GHC.Internal.Data.Bool.bool' 'id')@. +-- It is equivalent to @'flip' ('Data.Bool.bool' 'id')@. -- -- ==== __Examples__ -- ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Type/Bool.hs ===================================== @@ -1,7 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PolyKinds #-} -{-# LANGUAGE Safe #-} +{-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeFamilyDependencies #-} {-# LANGUAGE TypeOperators #-} @@ -23,7 +23,7 @@ module GHC.Internal.Data.Type.Bool ( If, type (&&), type (||), Not ) where -import GHC.Internal.Data.Bool +import GHC.Internal.Base -- This needs to be in base because (&&) is used in Data.Type.Equality. -- The other functions do not need to be in base, but seemed to be appropriate ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Type/Ord.hs ===================================== @@ -34,14 +34,11 @@ module GHC.Internal.Data.Type.Ord ( , OrdCond ) where -import GHC.Internal.Show(Show(..)) +import GHC.Internal.Base +import GHC.Internal.Show (Show(..)) import GHC.Internal.TypeError import GHC.Internal.TypeLits.Internal import GHC.Internal.TypeNats.Internal -import GHC.Internal.Types (type (~), Char) -import GHC.Internal.Data.Bool -import GHC.Internal.Data.Eq -import GHC.Internal.Data.Ord -- | 'Compare' branches on the kind of its arguments to either compare by -- 'Symbol' or 'Nat'. ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Version.hs ===================================== @@ -37,13 +37,12 @@ module GHC.Internal.Data.Version ( ) where import GHC.Internal.Data.Functor ( Functor(..) ) -import GHC.Internal.Data.Bool ( (&&) ) import GHC.Internal.Data.Eq import GHC.Internal.Int ( Int ) import GHC.Internal.Data.List ( map, sort, concat, concatMap, intersperse, (++) ) import GHC.Internal.Data.Ord import GHC.Internal.Data.String ( String ) -import GHC.Internal.Base ( Applicative(..) ) +import GHC.Internal.Base ( Applicative(..), (&&) ) import GHC.Internal.Generics import GHC.Internal.Unicode ( isDigit, isAlphaNum ) import GHC.Internal.Read ===================================== libraries/ghc-internal/src/GHC/Internal/IO/FD.hs ===================================== @@ -49,7 +49,6 @@ import GHC.Internal.Conc.IO import GHC.Internal.IO.Exception #if defined(mingw32_HOST_OS) import GHC.Internal.Windows -import GHC.Internal.Data.Bool import GHC.Internal.IO.SubSystem (()) import GHC.Internal.Foreign.Storable #endif ===================================== libraries/ghc-internal/src/GHC/Internal/JS/Prim.hs ===================================== @@ -46,7 +46,6 @@ import qualified GHC.Internal.Exception as Ex import qualified GHC.Internal.Exts as Exts import qualified GHC.Internal.CString as GHC import GHC.Internal.IO -import GHC.Internal.Data.Bool import GHC.Internal.Base import GHC.Internal.Show ===================================== libraries/ghc-internal/src/GHC/Internal/System/IO/OS.hs ===================================== @@ -29,7 +29,7 @@ import GHC.Internal.Control.Exception (mask) import GHC.Internal.Data.Function (const, (.), ($)) import GHC.Internal.Data.Functor (fmap) #if defined(mingw32_HOST_OS) -import GHC.Internal.Data.Bool (otherwise) +import GHC.Internal.Base (otherwise) #endif import GHC.Internal.Data.Maybe (Maybe (Nothing), maybe) #if defined(mingw32_HOST_OS) ===================================== libraries/ghc-internal/src/GHC/Internal/TH/Lift.hs ===================================== @@ -34,7 +34,6 @@ import GHC.Internal.TH.Monad import qualified GHC.Internal.TH.Lib as Lib (litE) -- See wrinkle (W4) of Note [Tracking dependencies on primitives] import GHC.Internal.Data.Either -import GHC.Internal.Data.Bool import GHC.Internal.Base hiding (NonEmpty(..), Type, Module, inline) import GHC.Internal.Data.NonEmpty (NonEmpty(..)) import GHC.Internal.Integer ===================================== libraries/ghc-internal/src/GHC/Internal/TypeError.hs ===================================== @@ -31,8 +31,7 @@ module GHC.Internal.TypeError , Unsatisfiable, unsatisfiable ) where -import GHC.Internal.Data.Bool -import GHC.Internal.Types (TYPE, Constraint, Symbol) +import GHC.Internal.Types (TYPE, Bool(True), Constraint, Symbol) {- Note [Custom type errors] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== testsuite/tests/interface-stability/base-exports.stdout ===================================== @@ -746,7 +746,7 @@ module Data.Bits where toIntegralSized :: forall a b. (GHC.Internal.Real.Integral a, GHC.Internal.Real.Integral b, Bits a, Bits b) => a -> GHC.Internal.Maybe.Maybe b module Data.Bool where - -- Safety: Safe + -- Safety: Trustworthy (&&) :: Bool -> Bool -> Bool type Bool :: * data Bool = False | True @@ -1308,7 +1308,7 @@ module Data.Kind where type Type = TYPE GHC.Internal.Types.LiftedRep module Data.List where - -- Safety: Safe + -- Safety: Trustworthy (!!) :: forall a. GHC.Internal.Stack.Types.HasCallStack => [a] -> GHC.Internal.Types.Int -> a (!?) :: forall a. [a] -> GHC.Internal.Types.Int -> GHC.Internal.Maybe.Maybe a (++) :: forall a. [a] -> [a] -> [a] ===================================== testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs ===================================== @@ -746,7 +746,7 @@ module Data.Bits where toIntegralSized :: forall a b. (GHC.Internal.Real.Integral a, GHC.Internal.Real.Integral b, Bits a, Bits b) => a -> GHC.Internal.Maybe.Maybe b module Data.Bool where - -- Safety: Safe + -- Safety: Trustworthy (&&) :: Bool -> Bool -> Bool type Bool :: * data Bool = False | True @@ -1308,7 +1308,7 @@ module Data.Kind where type Type = TYPE GHC.Internal.Types.LiftedRep module Data.List where - -- Safety: Safe + -- Safety: Trustworthy (!!) :: forall a. GHC.Internal.Stack.Types.HasCallStack => [a] -> GHC.Internal.Types.Int -> a (!?) :: forall a. [a] -> GHC.Internal.Types.Int -> GHC.Internal.Maybe.Maybe a (++) :: forall a. [a] -> [a] -> [a] ===================================== testsuite/tests/interface-stability/base-exports.stdout-mingw32 ===================================== @@ -746,7 +746,7 @@ module Data.Bits where toIntegralSized :: forall a b. (GHC.Internal.Real.Integral a, GHC.Internal.Real.Integral b, Bits a, Bits b) => a -> GHC.Internal.Maybe.Maybe b module Data.Bool where - -- Safety: Safe + -- Safety: Trustworthy (&&) :: Bool -> Bool -> Bool type Bool :: * data Bool = False | True @@ -1308,7 +1308,7 @@ module Data.Kind where type Type = TYPE GHC.Internal.Types.LiftedRep module Data.List where - -- Safety: Safe + -- Safety: Trustworthy (!!) :: forall a. GHC.Internal.Stack.Types.HasCallStack => [a] -> GHC.Internal.Types.Int -> a (!?) :: forall a. [a] -> GHC.Internal.Types.Int -> GHC.Internal.Maybe.Maybe a (++) :: forall a. [a] -> [a] -> [a] ===================================== testsuite/tests/interface-stability/base-exports.stdout-ws-32 ===================================== @@ -746,7 +746,7 @@ module Data.Bits where toIntegralSized :: forall a b. (GHC.Internal.Real.Integral a, GHC.Internal.Real.Integral b, Bits a, Bits b) => a -> GHC.Internal.Maybe.Maybe b module Data.Bool where - -- Safety: Safe + -- Safety: Trustworthy (&&) :: Bool -> Bool -> Bool type Bool :: * data Bool = False | True @@ -1308,7 +1308,7 @@ module Data.Kind where type Type = TYPE GHC.Internal.Types.LiftedRep module Data.List where - -- Safety: Safe + -- Safety: Trustworthy (!!) :: forall a. GHC.Internal.Stack.Types.HasCallStack => [a] -> GHC.Internal.Types.Int -> a (!?) :: forall a. [a] -> GHC.Internal.Types.Int -> GHC.Internal.Maybe.Maybe a (++) :: forall a. [a] -> [a] -> [a] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/905e07ec13f90ae09576b99e711ceb7c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/905e07ec13f90ae09576b99e711ceb7c... You're receiving this email because of your account on gitlab.haskell.org.