[commit: ghc] master: Add Data.Version.makeVersion & `IsList Version` (5b8fa46)

git at git.haskell.org git at git.haskell.org
Fri Dec 19 12:12:32 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/5b8fa46ca37caa9ec83b217a697628135da34506/ghc

>---------------------------------------------------------------

commit 5b8fa46ca37caa9ec83b217a697628135da34506
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Fri Dec 19 11:08:09 2014 +0100

    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


>---------------------------------------------------------------

5b8fa46ca37caa9ec83b217a697628135da34506
 libraries/base/Data/Version.hs                                   | 8 ++++++++
 libraries/base/GHC/Exts.hs                                       | 7 +++++++
 libraries/base/changelog.md                                      | 6 ++++++
 .../overloadedlists/should_fail/overloadedlistsfail01.stderr     | 9 ++++++---
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/libraries/base/Data/Version.hs b/libraries/base/Data/Version.hs
index 3761d81..1a14fd0 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 93de419..2942678 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 00da7ce..76a6a19 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 9f3a832..6516beb 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]



More information about the ghc-commits mailing list