Skip to content

Instantly share code, notes, and snippets.

@shlevy
Last active April 19, 2020 01:39
Show Gist options
  • Save shlevy/ad551c23c49d93bf005ca68dbfd4d63f to your computer and use it in GitHub Desktop.
Save shlevy/ad551c23c49d93bf005ca68dbfd4d63f to your computer and use it in GitHub Desktop.
%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