Skip to content

Instantly share code, notes, and snippets.

@freddi301
Created July 19, 2024 22:53
Show Gist options
  • Save freddi301/8df643092016284492e52db0e53400c3 to your computer and use it in GitHub Desktop.
Save freddi301/8df643092016284492e52db0e53400c3 to your computer and use it in GitHub Desktop.
Example of idempotent function and related proof
interface Idempotent (action : stateType -> stateType) where
law : (state : stateType) -> let u = action state in action u = u
IncFrom : Nat -> Nat -> Nat
IncFrom original state = case decEq state original of
Yes _ => S state
No _ => state
{o : Nat} -> Idempotent (IncFrom o) where
law s with (decEq s o)
_ | Yes p with (decEq (S s) o) | (p)
_ | No _ | Refl = Refl
_ | (No p) = rewrite snd $ decEqContraIsNo p in Refl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment