-
Notifications
You must be signed in to change notification settings - Fork 260
Description
This issue may be regarded (and hence instantly dismissed) as a status:duplicate of #2509... but posted for 'documentation'/alternative implementation purposes.
I'm happy with the merged #2513 , fixing #2509 , and so too is the author of the OP. Thanks to @MatthewDaggitt for the speedy turnround time!
That said, a brain-worm has been worrying away at me as to whether a pattern-matching-free solution was available (slightly better abstraction wrt presentation/implementation of the Sublist relation...?), and it seems there is: relative to the existing solution in Data.List.Relation.Unary.All.Properties, we can refactor as follows
all⊆concat : (xss : List (List A)) → All (Sublist._⊆ (concat xss)) xss
all⊆concat {A = A} xss = All.tabulate xs∈xss⇒xs⊆concat[xss] where
xs∈xss⇒xs⊆concat[xss] : xs ∈ xss → xs Sublist.⊆ concat xss
xs∈xss⇒xs⊆concat[xss] {xs = xs} xs∈xss
with prf ← Sublist.concat⁺ (Sublist.map Sublist.⊆-reflexive (Sublist.from∈ xs∈xss))
rewrite List.++-identityʳ xs
= prf
(and further simplification may be even be possible in the definition of prf itself? The ⊆-reflexive step is to pass from a rather simple relation via map to the more complex iterated Sublist (Sublist R) ... so this seems to have the flavour of the triangular identities for Sublist as a suitable 'monad' on relations... but I can't quite see the details yet)
This suggests that we might, instead, refactor by lifting out the above where-bound lemma into a self-standing one in Data.List.Relation.Binary.Sublist.Propositional.Properties (maybe even in Setoid? but then the proposed refactoring seems to stumble on the parameterisation on the Setoid, and the lemma shifts from A to List A... :-(, so perhaps the answer is to pull back all the way to Heterogeneous.Properties?) of the form
xs∈xss⇒xs⊆concat[xss] : xs ∈ xss → xs ⊆ concat xss
xs∈xss⇒xs⊆concat[xss] {xs = xs} xs∈xss
with prf ← concat⁺ (Sublist.map ⊆-reflexive (from∈ xs∈xss))
rewrite List.++-identityʳ xs
= prfleaving the final implementation (under Data.List.Relation.Unary.All.Properties? or should this move as well?) simply as:
all⊆concat : (xss : List (List A)) → All (Sublist._⊆ (concat xss)) xss
all⊆concat {A = A} xss = All.tabulate Sublist.xs∈xss⇒xs⊆concat[xss]