Skip to content

Instantly share code, notes, and snippets.

@roehst
Last active December 9, 2018 23:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roehst/f87af1dabd2699762dec2657a20173f7 to your computer and use it in GitHub Desktop.
Save roehst/f87af1dabd2699762dec2657a20173f7 to your computer and use it in GitHub Desktop.
Simple verification in Idris

A very simple example of verification in Idris.

Try changing the turn function and see how it fails to typecheck.

There are 2 other ways to make the properties pass.

module Main
data Direction = North | South | West | East
turn : Direction -> Direction
turn North = East
turn South = West
turn West = North
turn East = South
iter : (n: Nat) -> (f: a -> a) -> a -> a
iter Z _ x = x
iter (S k) f x = iter k f (f x)
prop_turn : (d : Direction) -> (iter 4 Main.turn d) = d
prop_turn North = Refl
prop_turn South = Refl
prop_turn West = Refl
prop_turn East = Refl
prop_not_idempotent : (d : Direction) -> Not (turn d = d)
prop_not_idempotent North Refl impossible
prop_not_idempotent South Refl impossible
prop_not_idempotent West Refl impossible
prop_not_idempotent East Refl impossible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment