-
Notifications
You must be signed in to change notification settings - Fork 247
Qualified imports in Data.Integer.Divisibility
fixing #2280
#2294
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that this doesn't cause clashes if people have both
Data.Nat.Divisibility
andData.Integer.Divisibility
in scope?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, in some sense, I think it is worse than that, in that it will cause clashes (unless there's something I don't understand), so this is perhaps Not The Right Answer.
That said, I would worry about any context in which each of
Data.Nat.Divisibility
andData.Integer.Divisibility
were in scope unqualified, because this would cause a separate (dis-)ambiguation problem wrt the relation symbol_|_
itself.In fact,
Data.Integer.Divisibility.Signed
does import both modules, but qualified, in the service of defining, and proving properties of,_|_
on the signed representation ofℤ
, which also introducesdivides
as a constructor...! And that does work fine, because each module is imported qualified, and indeed, the imported constructor is used only in two places, in the definitions of∣ᵤ⇒∣
and∣⇒∣ᵤ
;-) My PR currently disambiguates the pun ondivides
by reusingℕ.divides
in those definitions, but (of course!?) usingUnsigned.divides
works as well, and perhaps better 'respects the abstraction barrier' at play here.And indeed, in the spirit of other 'style' comments, I've simplified a complicated qualified import with a
using
and arenaming
directive, in favour of a simpler qualified import and then using it in place to appropriately disambiguate the puns.I think the existing (legacy) design is a hack to 'overload'/'borrow' the constructor for one definition, that of
_|_
onℕ
, and turn it into a constructor for_|_
onℤ
. This is fine (I don't like it, but meh; puns considered harmful as a programming idiom) on the current model of untyped patterns/pattern synonyms. But I think that if we ever move to a typed model of pattern matching, then this shouldn't be OK? (or could it be?)The problem, as I understand it, is to find a way to 'export' the constructor, for the (unsigned)
Integer.Divisibility
context, in such a way that it is type-correct for the definition of_|_
onℤ
. My solution, which I admit I perhaps did not think hard enough about, nor long enough, was to make this 'shallow' copy, and to use qualified import to explicitly disambiguate. But I'm not sure I know how to do better than the original, in my view hacky, design. Advice welcome!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed the 'better' disambiguation, and a note in
CHANGELOG
.But that doesn't resolve the question of whether this is the 'right' way to solve the problem... client modules (none in
stdlib
) which exploit the pun on import will break, I guess, so I'll add thebreaking
label?UPDATED: and, unfortunately, it's still a breaking change (but perhaps a 'lesser' one) not to introduce the synonym at all (and revert to the use of
ℕ.divides
inData.Integer.Divisibility.Signed
), which I had also, briefly, considered, until thinking "clients might still need/expect/want to see that constructor in scope; yuk!"... ;-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Half-way house: put a
{-# WARNING_ON_USAGE #-}
fordivides
(*not*
a deprecation per se) in favour ofℕ.divides
for v2.1, and then make the breaking change in v3.0?The imports in
...Signed
can be fixed as in the PR, and this would leave a hint to downstream clients to migrate their code ahead of v3.0?