How to use Read for Data.Version

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Sat Aug 14 17:10:49 UTC 2021


On Sat, Aug 14, 2021 at 06:53:08PM +0200, Andreas Abel wrote:
> How is the parser for Data.Version supposed to work?
> 
> ```haskell
> import Data.Version
> 
> readVersion :: String -> Version
> readVersion = read
> 
> main :: IO ()
> main = print $ readVersion "8.10.5"
> 
> -- *** Exception: Prelude.read: no parse
> ```

The Read instance is derived

    https://hackage.haskell.org/package/base-4.15.0.0/docs/src/Data-Version.html#Version

so it behaves like any other derived Read instance:

    Prelude Data.Version> read "Version {versionBranch = [8,10,5], versionTags = []}" :: Version
    Version {versionBranch = [8,10,5], versionTags = []}

Tom


More information about the Libraries mailing list