Last active
April 19, 2020 01:39
-
-
Save shlevy/ad551c23c49d93bf005ca68dbfd4d63f to your computer and use it in GitHub Desktop.
This file contains 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
%default total | |
data DecreasingArg : List a -> Type where | |
Base : DecreasingArg [] | |
Recurse : DecreasingArg xs -> ({y : List a} -> [] = y -> DecreasingArg y) -> DecreasingArg {a} (x :: xs) | |
toDecreasingArg : (l : List a) -> DecreasingArg l | |
toDecreasingArg [] = Base | |
toDecreasingArg (_ :: xs) = | |
Recurse (toDecreasingArg xs) g | |
where | |
g : {y : List a} -> [] = y -> DecreasingArg y | |
g Refl = Base | |
f : List a -> List a | |
f l = getWitness (f' l (toDecreasingArg l)) | |
where | |
f' : (l : List a) -> .(DecreasingArg l) -> Subset (List a) (\x => [] = x) | |
f' [] Base = Element [] Refl | |
f' (x :: xs) (Recurse dxs pfn) = case (f' xs dxs) of | |
(Element y p) => f' y (pfn p) -- Note that we match on 'p' here, not Refl. Refl would work but is cheating for the general case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment