Commit 5b8fa46c authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

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
parent cf594fd2
......@@ -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 []
......@@ -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
......@@ -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 `(<$>)`
......
......@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment