-
Notifications
You must be signed in to change notification settings - Fork 259
Improve Data.List.Base (fix #2359; deprecate use of with #2123)
#2365
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -943,13 +943,13 @@ module _ {P : Pred A p} (P? : Decidable P) where | |
| filter-all : ∀ {xs} → All P xs → filter P? xs ≡ xs | ||
| filter-all {[]} [] = refl | ||
| filter-all {x ∷ xs} (px ∷ pxs) with P? x | ||
| ... | no ¬px = contradiction px ¬px | ||
| ... | true because _ = cong (x ∷_) (filter-all pxs) | ||
| ... | false because [¬px] = contradiction px (invert [¬px]) | ||
| ... | true because _ = cong (x ∷_) (filter-all pxs) | ||
|
|
||
| filter-notAll : ∀ xs → Any (∁ P) xs → length (filter P? xs) < length xs | ||
| filter-notAll (x ∷ xs) (here ¬px) with P? x | ||
| ... | false because _ = s≤s (length-filter xs) | ||
| ... | yes px = contradiction px ¬px | ||
| ... | false because _ = s≤s (length-filter xs) | ||
| ... | true because [px] = contradiction (invert [px]) ¬px | ||
| filter-notAll (x ∷ xs) (there any) with ih ← filter-notAll xs any | does (P? x) | ||
| ... | false = m≤n⇒m≤1+n ih | ||
| ... | true = s≤s ih | ||
|
|
@@ -965,8 +965,8 @@ module _ {P : Pred A p} (P? : Decidable P) where | |
| filter-none : ∀ {xs} → All (∁ P) xs → filter P? xs ≡ [] | ||
| filter-none {[]} [] = refl | ||
| filter-none {x ∷ xs} (¬px ∷ ¬pxs) with P? x | ||
| ... | false because _ = filter-none ¬pxs | ||
| ... | yes px = contradiction px ¬px | ||
| ... | false because _ = filter-none ¬pxs | ||
| ... | true because [px] = contradiction (invert [px]) ¬px | ||
|
|
||
| filter-complete : ∀ {xs} → length (filter P? xs) ≡ length xs → | ||
| filter P? xs ≡ xs | ||
|
|
@@ -977,13 +977,13 @@ module _ {P : Pred A p} (P? : Decidable P) where | |
|
|
||
| filter-accept : ∀ {x xs} → P x → filter P? (x ∷ xs) ≡ x ∷ (filter P? xs) | ||
| filter-accept {x} Px with P? x | ||
| ... | true because _ = refl | ||
| ... | no ¬Px = contradiction Px ¬Px | ||
| ... | true because _ = refl | ||
| ... | false because [¬Px] = contradiction Px (invert [¬Px]) | ||
|
|
||
| filter-reject : ∀ {x xs} → ¬ P x → filter P? (x ∷ xs) ≡ filter P? xs | ||
| filter-reject {x} ¬Px with P? x | ||
| ... | yes Px = contradiction Px ¬Px | ||
| ... | false because _ = refl | ||
| ... | true because [Px] = contradiction (invert [Px]) ¬Px | ||
| ... | false because _ = refl | ||
|
|
||
| filter-idem : filter P? ∘ filter P? ≗ filter P? | ||
| filter-idem [] = refl | ||
|
|
@@ -1021,13 +1021,13 @@ module _ {R : Rel A p} (R? : B.Decidable R) where | |
|
|
||
| derun-reject : ∀ {x y} xs → R x y → derun R? (x ∷ y ∷ xs) ≡ derun R? (y ∷ xs) | ||
| derun-reject {x} {y} xs Rxy with R? x y | ||
| ... | yes _ = refl | ||
| ... | no ¬Rxy = contradiction Rxy ¬Rxy | ||
| ... | true because _ = refl | ||
| ... | false because [¬Rxy] = contradiction Rxy (invert [¬Rxy]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this better? Naively the previous version 'looked' better.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #2149 but for a TL;DR justification: I have never liked the asymmetry of having case branches which use constructors which mix different synonyms, such as Since this PR is part of a suite aimed at removing unnecessary
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, inconsistent branches are bad - but here they were doing So I'm happy with many of the other changes, it's this particular one which puzzles me. (I'm not saying you're wrong, merely that I'm not understanding your justification for the changes here.) I guess I'm not seeing the eager / lazy part. I don't want to hold up merging this, it doesn't feel like something worth arguing about, but I would like to understand.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for saying this! But I think this is perhaps a self-inflicted wound which I should attempt to patch by reverting these changes, which don't really belong here.
I think that they ought to happen at some point (one reason I opened #2149 all those months ago... :-(), but here is not the place. So let's discuss separately, and hopefully be able to make progress downstream.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I take your cue about cross-function uniformity (which I had also been going for... that's the second part of the changes, towards eliminating
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er... now I'm not sure what to do. I've reverted the changes for I think that I lacked the courage of my convictions to try to defend the shift from (more) strict to less in these proofs, and indeed, in proofs the issue might be moot, but there's a running theme in the history of In all the example uses in this module, the 'positive' case is lazy (the Now I can fully believe that I have misconstrued the role of strictness here (and indeed, perhaps a truly lazy evaluator could discern As things stand, neither in the status quo ante nor in these revised proofs, is there yet any attempt to replace these uses of ... but if you're serious about replacing uses of Sorry for such a long essay! I don't know how to distil a TL;DR for you!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say that the underlying issue was lack of understanding (of this reviewer) of the subtleties of the evaluation semantics (eager / lazy) involved, and the clear desire for things that are "pure" computations to never force the proof, since it's just going to be discarded anyways. Part of my issue might be my shallow undertanding of all these syntax patterns and the overall effect they have. I think the conversation has unearthed non-trivial design choices that ought to be better documented. I think your above essay has done a good job of pushing me towards 'your take' on what design is the better one. In (unpublished, sigh) work of a long time ago, we used the words 'verdict' and 'rationale' for what is essentially 'does' and 'proof'. Maybe introducing some wrappers around
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the 'verdict'/'rationale' separation of concerns! As to being 'better documented', I think that Eg. the factorisation of record Decidable A : Set _ where
constructor justified
field
verdict : Bool
rationale : if verdict then A else ¬ A(perhaps it was like this, once upon a time? cf. endless discussion about As to laziness wrt the |
||
|
|
||
| derun-accept : ∀ {x y} xs → ¬ R x y → derun R? (x ∷ y ∷ xs) ≡ x ∷ derun R? (y ∷ xs) | ||
| derun-accept {x} {y} xs ¬Rxy with R? x y | ||
| ... | yes Rxy = contradiction Rxy ¬Rxy | ||
| ... | no _ = refl | ||
| ... | true because [Rxy] = contradiction (invert [Rxy]) ¬Rxy | ||
| ... | false because _ = refl | ||
|
Comment on lines
+1029
to
+1030
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. presumably? |
||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- partition | ||
|
|
@@ -1040,7 +1040,7 @@ module _ {P : Pred A p} (P? : Decidable P) where | |
| ... | true = cong (Product.map (x ∷_) id) ih | ||
| ... | false = cong (Product.map id (x ∷_)) ih | ||
|
|
||
| length-partition : ∀ xs → (let (ys , zs) = partition P? xs) → | ||
| length-partition : ∀ xs → (let ys , zs = partition P? xs) → | ||
| length ys ≤ length xs × length zs ≤ length xs | ||
| length-partition [] = z≤n , z≤n | ||
| length-partition (x ∷ xs) with ih ← length-partition xs | does (P? x) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.