coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Thomas Strathmann <thomas AT pdp7.org>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Monads in Coq
- Date: Fri, 18 Feb 2011 19:12:04 +0100
On 2/18/11 18:21 , AUGER Cedric wrote:
I wanted to learn what is a monad, so I read some tutorial on it and
wrote this implementation in Coq
(http://coq.inria.fr/cocorico/AUGER_Monad).
Nice. Attached is an implementation of the list monad I adapted from a small exercise I did a while ago. Perhaps it's useful if you plan on building a sort of library around monads like the Haskell one.
Thomas
--
Thomas S. Strathmann http://pdp7.org/blog/
Require Import List.
Instance ListMonad : Monad list :=
{|
return_ := fun (A : Type) (a : A) => a :: nil;
bind := fun (A : Type) (m : list A) (B : Type) (f : A -> list B) =>
flat_map f m
|}.
(* right unit *)
induction a.
simpl.
reflexivity.
simpl.
rewrite <- IHa.
reflexivity.
(* left unit *)
intros.
simpl.
rewrite <- app_nil_end.
reflexivity.
(* associativity *)
induction ma.
simpl.
trivial.
intros.
simpl.
cut (flat_map g (f a ++ flat_map f ma) =
flat_map g (f a) ++ flat_map g (flat_map f ma)).
intros.
rewrite H.
rewrite IHma.
reflexivity.
induction (f a).
simpl.
reflexivity.
simpl.
rewrite IHl.
rewrite app_ass.
reflexivity.
Defined.
- [Coq-Club] "Anomaly" with crush, Chris Casinghino
- Re: [Coq-Club] "Anomaly" with crush,
Adam Chlipala
- Re: [Coq-Club] "Anomaly" with crush,
Chris Casinghino
- Re: [Coq-Club] "Anomaly" with crush,
Tom Prince
- [Coq-Club] Monads in Coq,
AUGER Cedric
- Re: [Coq-Club] Monads in Coq,
alexandre p
- Re: [Coq-Club] Monads in Coq, Adam Chlipala
- Re: [Coq-Club] Monads in Coq, Thomas Strathmann
- Re: [Coq-Club] Monads in Coq,
alexandre p
- [Coq-Club] Monads in Coq,
AUGER Cedric
- Re: [Coq-Club] "Anomaly" with crush,
Tom Prince
- Re: [Coq-Club] "Anomaly" with crush,
Chris Casinghino
- Re: [Coq-Club] "Anomaly" with crush,
Adam Chlipala
Archive powered by MhonArc 2.6.16.