Skip to content

Instantly share code, notes, and snippets.

@rrnewton
Created November 23, 2013 19:50
Show Gist options
  • Save rrnewton/7619107 to your computer and use it in GitHub Desktop.
Save rrnewton/7619107 to your computer and use it in GitHub Desktop.
An idris warm-up. Show this finite function forms a semi-lattice.
data AndState = Bot | TrueBot | BotTrue | TrueTrue | F
total
myjoin : AndState -> AndState -> AndState
myjoin TrueBot BotTrue = TrueTrue
myjoin TrueTrue TrueBot = TrueTrue
myjoin TrueTrue BotTrue = TrueTrue
myjoin Bot x = x
myjoin F _ = F
-- myjoin x y = myjoin y x
-- Manuallly writing all these out for the totality checker:
myjoin BotTrue TrueBot = TrueTrue
myjoin TrueBot TrueTrue = TrueTrue
myjoin BotTrue TrueTrue = TrueTrue
myjoin x Bot = x
myjoin _ F = F
-- Manually writing out reflexive cases too:
myjoin TrueBot TrueBot = TrueBot
myjoin BotTrue BotTrue = BotTrue
myjoin TrueTrue TrueTrue = TrueTrue
comm : (a:AndState) -> (b:AndState) -> (myjoin a b = myjoin b a)
comm Bot TrueBot = ?comm1
comm a b = ?comm2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment