Data.Version.parseVersion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Data.Version.parseVersion

Einar Karttunen
Hello

What is the correct way to use Data.Version.parseVersion?
It seems to start with the "wrong" result and the last one
is the intended one. e.g. "1.2.3" is parsed as:

[(Version {versionBranch = [1], versionTags = []},".2.3"),
 (Version {versionBranch = [1,2], versionTags = []},".3"),
 (Version {versionBranch = [1,2,3], versionTags = []},"")]

This is different from the usual read instances. Is the
behaviour intended? Should I just use that as:

filter (null . snd) $ readP_to_S parseVersion "1.2.3" :: [(Version,String)]


- Einar Karttunen
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.Version.parseVersion

Simon Marlow
Einar Karttunen wrote:

> What is the correct way to use Data.Version.parseVersion?
> It seems to start with the "wrong" result and the last one
> is the intended one. e.g. "1.2.3" is parsed as:
>
> [(Version {versionBranch = [1], versionTags = []},".2.3"),
>  (Version {versionBranch = [1,2], versionTags = []},".3"),
>  (Version {versionBranch = [1,2,3], versionTags = []},"")]
>
> This is different from the usual read instances. Is the
> behaviour intended? Should I just use that as:
>
> filter (null . snd) $ readP_to_S parseVersion "1.2.3" :: [(Version,String)]

It was intentional, but I'm prepared to be persuaded that it should be
done differently.  The problem is that all the parses are valid, it just
depends how much of the string you want to munch.  Perhaps the parser
should just be greedy.

You can't really compare this to other Read instances - for good reasons
this isn't the Read insance for Data.Version.  It's just a custom parser
for versions.

Cheers,
        Simon

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries