Section Encode_sum.
Variable (X Y : Type).
Inductive sigSum (sigX sigY : Type) : Type :=
| sigSum_X (s : sigX)
| sigSum_Y (s : sigY)
| sigSum_inl
| sigSum_inr
.
Arguments sigSum_inl {sigX sigY}. Arguments sigSum_inr {sigX sigY}. Arguments sigSum_X {sigX sigY}. Arguments sigSum_Y {sigX sigY}.
Global Instance Retract_sigSum_X (sigX sigY tau : Type) (f : Retract sigX tau) : Retract sigX (sigSum tau sigY).
Variable (sigX sigY : Type).
Hypothesis (cX : codable sigX X) (cY : codable sigY Y).
Global Instance Encode_sum : codable (sigSum sigX sigY) (X+Y) :=
{|
encode s := match s with
| inl x => sigSum_inl :: (Encode_map _ _ x)
| inr y => sigSum_inr :: (Encode_map _ _ y)
end
|}.
Definition Encode_sum_size (s:X+Y) :=
match s with
| inl x => S (size x)
| inr y => S (size y)
end.
End Encode_sum.
Arguments sigSum_inl {sigX sigY}. Arguments sigSum_inr {sigX sigY}. Arguments sigSum_X {sigX sigY}. Arguments sigSum_Y {sigX sigY}.
Hint Extern 4 (finTypeC (EqType (sigSum _ _))) => eapply sigSum_fin : typeclass_instances.
(* Check FinType (EqType (sigSum bool bool)). *)

Lemma cons_injective (X : Type) (x1 x2 : X) (l1 l2 : list X) :
x1 :: l1 = x2 :: l2 -> x1 = x2 /\ l1 = l2.