Skip to content

Instantly share code, notes, and snippets.

@LeifW
Last active August 29, 2015 14:02
Show Gist options
  • Save LeifW/aacd29f5336d19eea230 to your computer and use it in GitHub Desktop.
Save LeifW/aacd29f5336d19eea230 to your computer and use it in GitHub Desktop.
Use of postulate in Idris typeclass law
%default total
class Semigroupy a where
op: a -> a -> a
semigroupOpIsAssociative : (x, y, z : a) -> op x (op y z) = op (op x y) z
instance Semigroupy Int where
op = (+)
semigroupOpIsAssociative x y z = believe_me "sure, yeah, whatever"
{-
A problem with that is that now the value of the proof is that string.
Which could break anything expecting the more usual value, "refl".
Using "postulate" instead doesn't have that problem, because it doesn't reduce (no value).
-}
instance Semigroupy Integer where
op = (+)
semigroupOpIsAssociative x y z = integerAssociative
where postulate integerAssociative : x + (y + z) = (x + y) + z
@steshaw
Copy link

steshaw commented May 30, 2014

Thanks such much for this, Leif.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment