
14 Aug
2021
14 Aug
'21
1:13 p.m.
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.