[Git][ghc/ghc][wip/T26865] ghc-internal: Move GHC.Internal.Data.Bool to base
Teo Camarasu pushed to branch wip/T26865 at Glasgow Haskell Compiler / GHC
Commits:
7a308655 by Teo Camarasu at 2026-02-17T21:16:24+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
- - - - -
29 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
- utils/haddock/html-test/ref/A.html
- utils/haddock/html-test/ref/Bug1004.html
- utils/haddock/html-test/ref/Bug1033.html
- utils/haddock/html-test/ref/Bug1103.html
- utils/haddock/html-test/ref/Bug548.html
- utils/haddock/html-test/ref/Bug923.html
- utils/haddock/html-test/ref/ConstructorPatternExport.html
- utils/haddock/html-test/ref/FunArgs.html
- utils/haddock/html-test/ref/Instances.html
- utils/haddock/html-test/ref/LinearTypes.html
- utils/haddock/html-test/ref/RedactTypeSynonyms.html
- utils/haddock/html-test/ref/T23616.html
- utils/haddock/html-test/ref/Test.html
- utils/haddock/html-test/ref/TypeFamilies3.html
Changes:
=====================================
libraries/base/src/Data/Bool.hs
=====================================
@@ -24,4 +24,39 @@ module Data.Bool
bool
) where
-import GHC.Internal.Data.Bool
\ No newline at end of file
+import Prelude (Bool(..), (&&), (||), not, otherwise)
+
+-- $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
=====================================
@@ -184,7 +184,7 @@ module Data.List
genericReplicate
) where
-import GHC.Internal.Data.Bool (otherwise)
+import Data.Bool (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 Data.Bool (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
@@ -717,7 +716,7 @@ asyncReadRawBufferPtr loc !fd !buf !off !len = do
if l == (-1)
then let sock_errno = c_maperrno_func (fromIntegral rc)
non_sock_errno = Errno (fromIntegral rc)
- errno = bool non_sock_errno sock_errno (fdIsSocket fd)
+ errno = if fdIsSocket fd then sock_errno else non_sock_errno
in ioError (errnoToIOError loc errno Nothing Nothing)
else return (fromIntegral l)
@@ -728,7 +727,7 @@ asyncWriteRawBufferPtr loc !fd !buf !off !len = do
if l == (-1)
then let sock_errno = c_maperrno_func (fromIntegral rc)
non_sock_errno = Errno (fromIntegral rc)
- errno = bool non_sock_errno sock_errno (fdIsSocket fd)
+ errno = if fdIsSocket fd then sock_errno else non_sock_errno
in ioError (errnoToIOError loc errno Nothing Nothing)
else return (fromIntegral l)
@@ -740,7 +739,7 @@ blockingReadRawBufferPtr loc !fd !buf !off !len
let start_ptr = buf `plusPtr` off
recv_ret = c_safe_recv (fdFD fd) start_ptr (fromIntegral len) 0
read_ret = c_safe_read (fdFD fd) start_ptr (fromIntegral len)
- r <- bool read_ret recv_ret (fdIsSocket fd)
+ r <- if fdIsSocket fd then recv_ret else read_ret
when ((fdIsSocket fd) && (r == -1)) c_maperrno
return r
-- We trust read() to give us the correct errno but recv(), as a
@@ -753,7 +752,7 @@ blockingWriteRawBufferPtr loc !fd !buf !off !len
let start_ptr = buf `plusPtr` off
send_ret = c_safe_send (fdFD fd) start_ptr (fromIntegral len) 0
write_ret = c_safe_write (fdFD fd) start_ptr (fromIntegral len)
- r <- bool write_ret send_ret (fdIsSocket fd)
+ r <- if fdIsSocket fd then send_ret else write_ret
when (r == -1) c_maperrno
return r
-- We don't trust write() to give us the correct errno, and
=====================================
libraries/ghc-internal/src/GHC/Internal/JS/Prim.hs
=====================================
@@ -46,7 +46,6 @@ import GHC.Internal.Types
import qualified GHC.Internal.Exception as Ex
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
=====================================
@@ -1,4 +1,4 @@
-{-# LANGUAGE Safe #-}
+{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE RankNTypes #-}
@@ -23,14 +23,12 @@ module GHC.Internal.System.IO.OS
)
where
+import GHC.Internal.Base
import GHC.Internal.Control.Monad (return)
import GHC.Internal.Control.Concurrent.MVar (MVar)
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)
-#endif
import GHC.Internal.Data.Maybe (Maybe (Nothing), maybe)
#if defined(mingw32_HOST_OS)
import GHC.Internal.Data.Maybe (Maybe (Just))
=====================================
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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=====================================
utils/haddock/html-test/ref/A.html
=====================================
@@ -70,7 +70,7 @@
><li class="src short"
><a href="#"
>test2 :: :: <a href="#" title="GHC.Exts"
>Bool</a
></li
>
participants (1)
-
Teo Camarasu (@teo)