summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeo Camarasu <teofilcamarasu@gmail.com>2022-05-02 11:13:04 +0100
committerTeo Camarasu <teofilcamarasu@gmail.com>2022-05-29 12:25:39 +0000
commit0092c67cffb707611b2684df24a1a77e40c01cb7 (patch)
treee2f600a72b6c7e688f9806329f0abe5fa655d260
parentfbf2f254ec85bd696859f939698edfaef8ff708c (diff)
downloadhaskell-0092c67cffb707611b2684df24a1a77e40c01cb7.tar.gz
export IsList from GHC.IsList
it is still re-exported from GHC.Exts
-rw-r--r--compiler/GHC/Builtin/Names.hs11
-rwxr-xr-xlibraries/base/GHC/Exts.hs71
-rw-r--r--libraries/base/GHC/IsList.hs87
-rw-r--r--libraries/base/base.cabal1
-rw-r--r--libraries/base/changelog.md2
-rw-r--r--testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr6
-rw-r--r--testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr4
-rw-r--r--testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr2
-rw-r--r--testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr2
-rw-r--r--testsuite/tests/showIface/Orphans.stdout8
10 files changed, 108 insertions, 86 deletions
diff --git a/compiler/GHC/Builtin/Names.hs b/compiler/GHC/Builtin/Names.hs
index 8aad951de0..6050ceac0d 100644
--- a/compiler/GHC/Builtin/Names.hs
+++ b/compiler/GHC/Builtin/Names.hs
@@ -544,7 +544,7 @@ gHC_PRIM, gHC_PRIM_PANIC, gHC_PRIM_EXCEPTION,
gHC_FLOAT, gHC_TOP_HANDLER, sYSTEM_IO, dYNAMIC,
tYPEABLE, tYPEABLE_INTERNAL, gENERICS,
rEAD_PREC, lEX, gHC_INT, gHC_WORD, mONAD, mONAD_FIX, mONAD_ZIP, mONAD_FAIL,
- aRROW, gHC_DESUGAR, rANDOM, gHC_EXTS,
+ aRROW, gHC_DESUGAR, rANDOM, gHC_EXTS, gHC_IS_LIST,
cONTROL_EXCEPTION_BASE, gHC_TYPEERROR, gHC_TYPELITS, gHC_TYPELITS_INTERNAL,
gHC_TYPENATS, gHC_TYPENATS_INTERNAL,
dATA_COERCE, dEBUG_TRACE, uNSAFE_COERCE :: Module
@@ -606,6 +606,7 @@ aRROW = mkBaseModule (fsLit "Control.Arrow")
gHC_DESUGAR = mkBaseModule (fsLit "GHC.Desugar")
rANDOM = mkBaseModule (fsLit "System.Random")
gHC_EXTS = mkBaseModule (fsLit "GHC.Exts")
+gHC_IS_LIST = mkBaseModule (fsLit "GHC.IsList")
cONTROL_EXCEPTION_BASE = mkBaseModule (fsLit "Control.Exception.Base")
gHC_GENERICS = mkBaseModule (fsLit "GHC.Generics")
gHC_TYPEERROR = mkBaseModule (fsLit "GHC.TypeError")
@@ -1473,10 +1474,10 @@ zipName = varQual gHC_LIST (fsLit "zip") zipIdKey
-- Overloaded lists
isListClassName, fromListName, fromListNName, toListName :: Name
-isListClassName = clsQual gHC_EXTS (fsLit "IsList") isListClassKey
-fromListName = varQual gHC_EXTS (fsLit "fromList") fromListClassOpKey
-fromListNName = varQual gHC_EXTS (fsLit "fromListN") fromListNClassOpKey
-toListName = varQual gHC_EXTS (fsLit "toList") toListClassOpKey
+isListClassName = clsQual gHC_IS_LIST (fsLit "IsList") isListClassKey
+fromListName = varQual gHC_IS_LIST (fsLit "fromList") fromListClassOpKey
+fromListNName = varQual gHC_IS_LIST (fsLit "fromListN") fromListNClassOpKey
+toListName = varQual gHC_IS_LIST (fsLit "toList") toListClassOpKey
-- HasField class ops
getFieldName, setFieldName :: Name
diff --git a/libraries/base/GHC/Exts.hs b/libraries/base/GHC/Exts.hs
index d9793d59d7..662bea8964 100755
--- a/libraries/base/GHC/Exts.hs
+++ b/libraries/base/GHC/Exts.hs
@@ -142,18 +142,16 @@ import GHC.ArrayArray
import GHC.Base hiding ( coerce )
import GHC.Ptr
import GHC.Stack
+import GHC.IsList (IsList(..)) -- for re-export
import qualified Data.Coerce
import Data.String
import Data.OldList
import Data.Data
import Data.Ord
-import Data.Version ( Version(..), makeVersion )
import qualified Debug.Trace
import Unsafe.Coerce ( unsafeCoerce# ) -- just for re-export
-import Control.Applicative (ZipList(..))
-
-- XXX This should really be in Data.Tuple, where the definitions are
maxTupleSize :: Int
maxTupleSize = 64
@@ -218,73 +216,6 @@ data SpecConstrAnnotation = NoSpecConstr | ForceSpecConstr
)
-{- **********************************************************************
-* *
-* The IsList class *
-* *
-********************************************************************** -}
-
--- | The 'IsList' class and its methods are intended to be used in
--- conjunction with the OverloadedLists extension.
---
--- @since 4.7.0.0
-class IsList l where
- -- | The 'Item' type function returns the type of items of the structure
- -- @l@.
- type Item l
-
- -- | The 'fromList' function constructs the structure @l@ from the given
- -- list of @Item l@
- fromList :: [Item l] -> l
-
- -- | The 'fromListN' function takes the input list's length and potentially
- -- uses it to construct the structure @l@ more efficiently compared to
- -- 'fromList'. If the given number does not equal to the input list's length
- -- the behaviour of 'fromListN' is not specified.
- --
- -- prop> fromListN (length xs) xs == fromList xs
- fromListN :: Int -> [Item l] -> l
- fromListN _ = fromList
-
- -- | The 'toList' function extracts a list of @Item l@ from the structure @l@.
- -- It should satisfy fromList . toList = id.
- toList :: l -> [Item l]
-
--- | @since 4.7.0.0
-instance IsList [a] where
- type (Item [a]) = a
- fromList = id
- toList = id
-
--- | @since 4.15.0.0
-instance IsList (ZipList a) where
- type Item (ZipList a) = a
- fromList = ZipList
- toList = getZipList
-
--- | @since 4.9.0.0
-instance IsList (NonEmpty a) where
- type Item (NonEmpty a) = a
-
- fromList (a:as) = a :| as
- fromList [] = errorWithoutStackTrace "NonEmpty.fromList: empty list"
-
- toList ~(a :| as) = a : as
-
--- | @since 4.8.0.0
-instance IsList Version where
- type (Item Version) = Int
- fromList = makeVersion
- toList = versionBranch
-
--- | Be aware that 'fromList . toList = id' only for unfrozen 'CallStack's,
--- since 'toList' removes frozenness information.
---
--- @since 4.9.0.0
-instance IsList CallStack where
- type (Item CallStack) = (String, SrcLoc)
- fromList = fromCallSiteList
- toList = getCallStack
-- | An implementation of the old @atomicModifyMutVar#@ primop in
-- terms of the new 'atomicModifyMutVar2#' primop, for backwards
diff --git a/libraries/base/GHC/IsList.hs b/libraries/base/GHC/IsList.hs
new file mode 100644
index 0000000000..fb93952f23
--- /dev/null
+++ b/libraries/base/GHC/IsList.hs
@@ -0,0 +1,87 @@
+{-# LANGUAGE Trustworthy #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE TypeFamilies #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module : GHC.IsList
+-- Copyright : (c) The University of Glasgow 2002
+-- License : see libraries/base/LICENSE
+--
+-- Maintainer : cvs-ghc@haskell.org
+-- Stability : internal
+-- Portability : non-portable (GHC Extensions)
+--
+-- @since 4.17.0.0
+-----------------------------------------------------------------------------
+
+module GHC.IsList
+ ( IsList(..)
+ ) where
+
+import GHC.Base
+import GHC.Stack
+import Data.Version ( Version(..), makeVersion )
+import Control.Applicative (ZipList(..))
+
+-- | The 'IsList' class and its methods are intended to be used in
+-- conjunction with the OverloadedLists extension.
+--
+-- @since 4.7.0.0
+class IsList l where
+ -- | The 'Item' type function returns the type of items of the structure
+ -- @l@.
+ type Item l
+
+ -- | The 'fromList' function constructs the structure @l@ from the given
+ -- list of @Item l@
+ fromList :: [Item l] -> l
+
+ -- | The 'fromListN' function takes the input list's length and potentially
+ -- uses it to construct the structure @l@ more efficiently compared to
+ -- 'fromList'. If the given number does not equal to the input list's length
+ -- the behaviour of 'fromListN' is not specified.
+ --
+ -- prop> fromListN (length xs) xs == fromList xs
+ fromListN :: Int -> [Item l] -> l
+ fromListN _ = fromList
+
+ -- | The 'toList' function extracts a list of @Item l@ from the structure @l@.
+ -- It should satisfy fromList . toList = id.
+ toList :: l -> [Item l]
+
+-- | @since 4.7.0.0
+instance IsList [a] where
+ type (Item [a]) = a
+ fromList = id
+ toList = id
+
+-- | @since 4.15.0.0
+instance IsList (ZipList a) where
+ type Item (ZipList a) = a
+ fromList = ZipList
+ toList = getZipList
+
+-- | @since 4.9.0.0
+instance IsList (NonEmpty a) where
+ type Item (NonEmpty a) = a
+
+ fromList (a:as) = a :| as
+ fromList [] = errorWithoutStackTrace "NonEmpty.fromList: empty list"
+
+ toList ~(a :| as) = a : as
+
+-- | @since 4.8.0.0
+instance IsList Version where
+ type (Item Version) = Int
+ fromList = makeVersion
+ toList = versionBranch
+
+-- | Be aware that 'fromList . toList = id' only for unfrozen 'CallStack's,
+-- since 'toList' removes frozenness information.
+--
+-- @since 4.9.0.0
+instance IsList CallStack where
+ type (Item CallStack) = (String, SrcLoc)
+ fromList = fromCallSiteList
+ toList = getCallStack
diff --git a/libraries/base/base.cabal b/libraries/base/base.cabal
index 7ecc17b3fa..cc6a8d4f20 100644
--- a/libraries/base/base.cabal
+++ b/libraries/base/base.cabal
@@ -249,6 +249,7 @@ Library
GHC.Int
GHC.Integer
GHC.Integer.Logarithms
+ GHC.IsList
GHC.Ix
GHC.List
GHC.Maybe
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 3762ebf4df..ba542ac58e 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -57,6 +57,8 @@
* Re-export `augment` and `build` function from `GHC.List`
+ * Re-export the `IsList` typeclass from the new `GHC.IsList` module.
+
## 4.16.1.0 *Feb 2022*
* Shipped with GHC 9.2.2
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
index e7daaeda0b..f3ccc3df17 100644
--- a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
+++ b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
@@ -14,10 +14,10 @@ overloadedlistsfail01.hs:5:8: error:
overloadedlistsfail01.hs:5:14: error:
• Ambiguous type variable ‘a0’ arising from an overloaded list
- prevents the constraint ‘(GHC.Exts.IsList a0)’ from being solved.
+ prevents the constraint ‘(GHC.IsList.IsList a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
Potentially matching instance:
- instance GHC.Exts.IsList [a] -- Defined in ‘GHC.Exts’
+ instance GHC.IsList.IsList [a] -- Defined in ‘GHC.IsList’
...plus four instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the first argument of ‘print’, namely ‘[1]’
@@ -27,7 +27,7 @@ overloadedlistsfail01.hs:5:14: error:
overloadedlistsfail01.hs:5:15: error:
• Ambiguous type variable ‘a0’ arising from the literal ‘1’
prevents the constraint ‘(Num
- (GHC.Exts.Item a0))’ from being solved.
+ (GHC.IsList.Item a0))’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
Potentially matching instances:
instance Num Integer -- Defined in ‘GHC.Num’
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr
index e0be7ab4e5..b1a7b24ba5 100644
--- a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr
+++ b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr
@@ -1,12 +1,12 @@
overloadedlistsfail02.hs:6:8: error:
- • No instance for (GHC.Exts.IsList Foo)
+ • No instance for (GHC.IsList.IsList Foo)
arising from an overloaded list
• In the expression: [7]
In an equation for ‘test’: test = [7]
overloadedlistsfail02.hs:6:9: error:
- • No instance for (Num (GHC.Exts.Item Foo))
+ • No instance for (Num (GHC.IsList.Item Foo))
arising from the literal ‘7’
• In the expression: 7
In the expression: [7]
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr
index 3ff4cb3678..1380dda229 100644
--- a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr
+++ b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr
@@ -1,7 +1,7 @@
overloadedlistsfail03.hs:3:28: error:
• Couldn't match type ‘[Char]’ with ‘Char’
- Expected: GHC.Exts.Item [Char]
+ Expected: GHC.IsList.Item [Char]
Actual: String
• In the expression: "b"
In the first argument of ‘length’, namely ‘(['a', "b"] :: [Char])’
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr
index 6f0045a462..1de0a59995 100644
--- a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr
+++ b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr
@@ -1,7 +1,7 @@
overloadedlistsfail05.hs:3:24: error:
• Couldn't match type ‘Char’ with ‘Int’
- Expected: GHC.Exts.Item [Int]
+ Expected: GHC.IsList.Item [Int]
Actual: Char
• In the expression: 'a'
In the first argument of ‘length’, namely
diff --git a/testsuite/tests/showIface/Orphans.stdout b/testsuite/tests/showIface/Orphans.stdout
index 08725b6715..fdb94e36e9 100644
--- a/testsuite/tests/showIface/Orphans.stdout
+++ b/testsuite/tests/showIface/Orphans.stdout
@@ -1,6 +1,6 @@
-instance [orphan] GHC.Exts.IsList [GHC.Types.Bool] = $fIsListBool
-instance GHC.Exts.IsList [X] = $fIsListX
-family instance GHC.Exts.Item [X] = D:R:ItemX
-family instance [orphan] GHC.Exts.Item [GHC.Types.Bool]
+instance [orphan] GHC.IsList.IsList [GHC.Types.Bool] = $fIsListBool
+instance GHC.IsList.IsList [X] = $fIsListX
+family instance GHC.IsList.Item [X] = D:R:ItemX
+family instance [orphan] GHC.IsList.Item [GHC.Types.Bool]
"myrule1" [orphan] forall @a.
"myrule2" GHC.Base.id @(X -> X) f = f