File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -95,10 +95,21 @@ Require Import ExtLib.Structures.Functor.
9595Require Import ExtLib.Structures.Monad.
9696Require Import ExtLib.Structures.Applicative.
9797
98+ Section traversable.
99+ Variable F : Type -> Type.
100+ Variable Applicative_F : Applicative F.
101+ Variable A B : Type.
102+ Variable f : A -> F B.
103+
104+ Fixpoint mapT_list (ls : list A) : F (list B) :=
105+ match ls with
106+ | nil => pure nil
107+ | l :: ls => ap (ap (pure (@cons B)) (f l)) (mapT_list ls)
108+ end .
109+ End traversable.
110+
98111Global Instance Traversable_list : Traversable list :=
99- { mapT := fun F _ A B f =>
100- List.fold_right (fun x acc => ap (ap (pure (@cons B)) (f x)) acc) (pure nil)
101- }.
112+ { mapT := @mapT_list }.
102113
103114Global Instance Monad_list : Monad list :=
104115{ ret := fun _ x => x :: nil
You can’t perform that action at this time.
0 commit comments