Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created April 24, 2014 15:08
Show Gist options
  • Save puffnfresh/11258181 to your computer and use it in GitHub Desktop.
Save puffnfresh/11258181 to your computer and use it in GitHub Desktop.
Verified monoid in Coq.
Inductive bool : Type :=
| true : bool
| false : bool.
Class Monoid (A : Type) :=
{
empty : A ;
append : A -> A -> A ;
left_neutrality : forall x, append empty x = x ;
right_neutrality : forall x, append x empty = x ;
associativity : forall x y z, append x (append y z) = append (append x y) z
}.
Program
Instance bool_Monoid : Monoid bool :=
{
empty := false ;
append a b := match a with
| true => true
| false => b
end
}.
Next Obligation.
intros.
reflexivity.
Qed.
Next Obligation.
intros.
destruct x.
reflexivity.
reflexivity.
Qed.
Next Obligation.
intros.
destruct x.
reflexivity.
destruct y.
reflexivity.
reflexivity.
Qed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment