-
Notifications
You must be signed in to change notification settings - Fork 702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Caret-style version range operator #3705
Conversation
LGTM. But I'll like to see tests. (which would break in parsec branch) |
/cc @dcoutts |
Would be nice to add a changelog note. |
ae63fb8
to
5036c46
Compare
This implements a new syntactic sugar: The version range operator `^>=` which is equivalent to `>=` intersected with an automatically inferred major upper bound. This new syntax is only allowed for `cabal-version: >=2.0`, and allows to describe the most common use of version bounds more conveniently: build-depends: foo ^>= 1.2.3.4, bar ^>= 1 The declaration above is exactly equivalent to build-depends: foo >= 1.2.3.4 && < 1.3, bar >= 1 && < 1.1 The `^`-symbol was chosen because it can serve as a mnemonic when the `>` sign is rotated and interpreted as "less than ceiling" Moreover, `^` appears to become a quasi-standard to denote morally equivalent operator that way in other language ecosystems which similiar to Haskell have adopted semantic versioning: - Node: https://nodesource.com/blog/semver-tilde-and-caret/ - Bower: https://bower.io/docs/api/#install - PHP: https://getcomposer.org/doc/articles/versions.md#caret Ruby, on the other hand, uses a Tilde operator (`~>`) for that purpose (but with a less robust semantic): - https://blog.codeship.com/optimists-guide-pessimistic-library-versioning And Python is currently planing to use an `~=` operator: - https://www.python.org/dev/peps/pep-0440/#compatible-release
5036c46
to
0f2193a
Compare
I've changed the syntax from @23Skidoo changelog entry added @phadej finally brought myself to try to come up with a simple parser test... getting there took longer than it should have... |
Thanks! So I think this can be merged once Travis is green. |
That’s a bit confusing since in other platforms semver.toComparators('^1.2.3')
// [ [ '>=1.2.3-0', '<2.0.0-0' ] ]
// compare upper limit for ~
semver.toComparators('~1.2.3')
// [ [ '>=1.2.3-0', '<1.3.0-0' ] ] I’d prefer to see |
Or maybe I’m missing something? |
In the haskell pvp (https://pvp.haskell.org/), which predates semver btw, the first two components indicate major version, while in semver, only the first component indicates major version. So semantically the caret operator means the same thing in both cases -- picking the range up to the next major version. It just so happens that "major version" covers a different number of components. |
This comment has been minimized.
This comment has been minimized.
@gbaz thanks for this clarification! |
This implements a new syntactic sugar: The version range operator
^>=
which is equivalent to>=
intersected with anautomatically inferred major upper bound.
This new syntax is only allowed for
cabal-version: >=2.0
, andallows to describe the most common use of version
bounds more conveniently:
The declaration above is exactly equivalent to
The
^
-symbol was chosen because it can serve as a mnemonic when the>
sign is rotated and interpreted as "less than ceiling"Moreover,
^
appears to become a quasi-standard to denote morallyequivalent operator that way in other language ecosystems which similiar
to Haskell have adopted semantic versioning:
Ruby, on the other hand, uses a Tilde operator (
~>
) for thatpurpose (but with a less robust semantic):
And Python is currently planing to use an
~=
operator: