I've been trying to create a small typeclass hierarchy in Coq and I haven't been able to progress despite there being a few answers on stackoverflow that I thought would be the solution, particularly Building a class hierarchy in Coq?.
Here is what I have:
Class Unfoldable (C : Type -> Type) (A : Type)
(insert : A -> C A -> C A)
(empty : C A) : Type :=
{
insert_neq : forall (x y : A) (h : C A),
insert x h <> insert y h -> x <> y;
empty_insert_eq : forall x y : A,
insert x empty = insert y empty <-> x = y
}.
Class Foldable (C : Type -> Type) (A B : Type)
(foldr : (A -> B -> B) -> B -> C A -> B) : Type :=
{
(* Foldable properties??? *)
}.
Class Collection C A {B} insert empty foldr
`{F : Foldable C A B foldr}
`{U : Unfoldable C A insert empty} :=
{
collection_id : forall h,
foldr insert empty h = h
}.
Print Collection.
And here is the error message:
Error:
In environment
Collection :
forall (C : Type -> Type) (A B : Type) (insert : A -> C A -> C A)
(empty : C A) (foldr : (A -> B -> B) -> B -> C A -> B),
Foldable C A B foldr -> Unfoldable C A insert empty -> Type
C : Type -> Type
A : Type
B : Type
insert : A -> C A -> C A
empty : C A
foldr : (A -> B -> B) -> B -> C A -> B
F : Foldable C A B foldr
U : Unfoldable C A insert empty
h : ?17
The term "insert" has type "A -> C A -> C A"
while it is expected to have type "A -> B -> B".
Shouldn't C A
have a type of Type
and therefore fit as B
?
Sorry about not being able to provide more information. I really don't know Coq well. Thanks for any help.