Skip to content

Instantly share code, notes, and snippets.

@harlanhaskins
Created September 25, 2017 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harlanhaskins/841acb5ab8735be5f871e39c31cb099f to your computer and use it in GitHub Desktop.
Save harlanhaskins/841acb5ab8735be5f871e39c31cb099f to your computer and use it in GitHub Desktop.
Definition bind_option (A: Type) (B: Type) (opt: option A) (f: A -> option B): option B :=
match opt with
| Some v => f v
| None => None
end.
Definition return_option (A: Type) (a: A) := Some a.
(* return a >>= f = f a *)
Theorem left_identity_option A B a f:
bind_option A B (return_option A a) f = f a.
Proof.
simpl.
reflexivity.
Qed.
(* m >>= return = m *)
Theorem right_identity_option A m:
bind_option A A m (return_option A) = m.
Proof.
induction m.
simpl.
reflexivity.
simpl.
reflexivity.
Qed.
(*
(m >>= f) >>= g = m >>= (\x -> (f x) >>= g)
*)
Theorem associativity_option A B C opt f g:
bind_option B C (bind_option A B opt f) g =
bind_option A C opt (fun x => bind_option B C (f x) g).
Proof.
induction opt.
simpl.
reflexivity.
simpl.
reflexivity.
Qed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment