
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 ``` P.S.: Maintainer libraries@haskell.org

Looking at the source code [1], Read is derived, and not using parseVersion
(which has the behaviour I think you expect).
You may want to use parseVersion directly.
[1]:
https://hackage.haskell.org/package/base-4.15.0.0/docs/src/Data-Version.html
On Sat, Aug 14, 2021, 11:55 Andreas Abel
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 ```
P.S.: Maintainer libraries@haskell.org _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Thanks for the quick answer. Indeed, I confused Read and ReadP! --Andreas On 2021-08-14 19:06, chessai wrote:
Looking at the source code [1], Read is derived, and not using parseVersion (which has the behaviour I think you expect).
You may want to use parseVersion directly.
[1]: https://hackage.haskell.org/package/base-4.15.0.0/docs/src/Data-Version.html https://hackage.haskell.org/package/base-4.15.0.0/docs/src/Data-Version.html
On Sat, Aug 14, 2021, 11:55 Andreas Abel
mailto:andreas.abel@ifi.lmu.de> 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 ```
P.S.: Maintainer libraries@haskell.org mailto:libraries@haskell.org _______________________________________________ Libraries mailing list Libraries@haskell.org mailto:Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

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... 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

On Sat, Aug 14, 2021 at 06:53:08PM +0200, Andreas Abel wrote:
readVersion :: String -> Version readVersion = read
main :: IO () main = print $ readVersion "8.10.5"
Perhaps this is close to what you want: λ> import Data.Version λ> import Text.ParserCombinators.ReadP λ> foldr (const . Just) Nothing $ readP_to_S (parseVersion <* eof) "8.10.5" Just (Version {versionBranch = [8,10,5], versionTags = []},"") λ> foldr (const . Just) Nothing $ readP_to_S (parseVersion <* eof) "8.10.X" Nothing λ> foldr (const . Just) Nothing $ readP_to_S (parseVersion <* eof) "8.10.5-foo-bar" Just (Version {versionBranch = [8,10,5], versionTags = ["foo","bar"]},"") [ foldr (const . Just) Nothing == listToMaybe) ] -- Viktor.
participants (4)
-
Andreas Abel
-
chessai
-
Tom Ellis
-
Viktor Dukhovni