summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2014-12-19 11:08:09 +0100
committerHerbert Valerio Riedel <hvr@gnu.org>2014-12-19 13:12:50 +0100
commit5b8fa46ca37caa9ec83b217a697628135da34506 (patch)
tree88c045a6c084f3958a670a27bf47724251fabc1f
parentcf594fd204f951f849e876cf28f6ac1604184ae7 (diff)
downloadhaskell-5b8fa46ca37caa9ec83b217a697628135da34506.tar.gz
Add Data.Version.makeVersion & `IsList Version`
These two facilities provide some means to avoid the double-breakage caused by first by the deprecation (see #2496), and then again by the actual future field-removal. See also https://groups.google.com/d/msg/haskell-core-libraries/q9H-QlL_gnE/4lbb_mBjre8J for details about this library addition. Reviewed By: ekmett Differential Revision: https://phabricator.haskell.org/D577
-rw-r--r--libraries/base/Data/Version.hs8
-rwxr-xr-xlibraries/base/GHC/Exts.hs7
-rw-r--r--libraries/base/changelog.md6
-rw-r--r--testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr9
4 files changed, 27 insertions, 3 deletions
diff --git a/libraries/base/Data/Version.hs b/libraries/base/Data/Version.hs
index 3761d81bb9..1a14fd08f4 100644
--- a/libraries/base/Data/Version.hs
+++ b/libraries/base/Data/Version.hs
@@ -32,6 +32,8 @@ module Data.Version (
Version(..),
-- * A concrete representation of @Version@
showVersion, parseVersion,
+ -- * Constructor function
+ makeVersion
) where
import Control.Monad ( Monad(..), liftM )
@@ -121,3 +123,9 @@ parseVersion :: ReadP Version
parseVersion = do branch <- sepBy1 (liftM read (munch1 isDigit)) (char '.')
tags <- many (char '-' >> munch1 isAlphaNum)
return Version{versionBranch=branch, versionTags=tags}
+
+-- | Construct tag-less 'Version'
+--
+-- @since 4.8.0.0
+makeVersion :: [Int] -> Version
+makeVersion b = Version b []
diff --git a/libraries/base/GHC/Exts.hs b/libraries/base/GHC/Exts.hs
index 93de419eb6..294267835e 100755
--- a/libraries/base/GHC/Exts.hs
+++ b/libraries/base/GHC/Exts.hs
@@ -84,6 +84,7 @@ import Data.String
import Data.OldList
import Data.Data
import Data.Ord
+import Data.Version ( Version(..), makeVersion )
import qualified Debug.Trace
-- XXX This should really be in Data.Tuple, where the definitions are
@@ -177,3 +178,9 @@ instance IsList [a] where
type (Item [a]) = a
fromList = id
toList = id
+
+-- | @since 4.8.0.0
+instance IsList Version where
+ type (Item Version) = Int
+ fromList = makeVersion
+ toList = versionBranch
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 00da7cee8b..76a6a191dd 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -12,6 +12,12 @@
* Add `System.Exit.die`
+ * Deprecate `versionTags` field of `Data.Version.Version`.
+ Add `makeVersion :: [Int] -> Version` constructor function to aid
+ migration to a future `versionTags`-less `Version`.
+
+ * Add `IsList Version` instance
+
* Weaken RealFloat constraints on some `Data.Complex` functions
* Add `Control.Monad.(<$!>)` as a strict version of `(<$>)`
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
index 9f3a8325c2..6516beb078 100644
--- a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
+++ b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
@@ -3,10 +3,11 @@ overloadedlistsfail01.hs:5:8:
No instance for (Show a0) arising from a use of ‘print’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
+ instance [safe] Show Data.Version.Version
+ -- Defined in ‘Data.Version’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
instance Show Ordering -- Defined in ‘GHC.Show’
- instance Show Integer -- Defined in ‘GHC.Show’
- ...plus 22 others
+ ...plus 23 others
In the expression: print [1]
In an equation for ‘main’: main = print [1]
@@ -14,7 +15,9 @@ overloadedlistsfail01.hs:5:14:
No instance for (GHC.Exts.IsList a0)
arising from an overloaded list
The type variable ‘a0’ is ambiguous
- Note: there is a potential instance available:
+ Note: there are several potential instances:
+ instance GHC.Exts.IsList Data.Version.Version
+ -- Defined in ‘GHC.Exts’
instance GHC.Exts.IsList [a] -- Defined in ‘GHC.Exts’
In the first argument of ‘print’, namely ‘[1]’
In the expression: print [1]