J'essaie de traiter des structures canoniques dans ssreflect. Il y a 2 morceaux de code que j'ai pris de here.Structures canoniques dans ssreflect
Je vais apporter des pièces pour le bool et les types d'options.
Section BoolFinType.
Lemma bool_enumP : Finite.axiom [:: true; false]. Proof. by case. Qed.
Definition bool_finMixin := Eval hnf in FinMixin bool_enumP.
Canonical bool_finType := Eval hnf in FinType bool bool_finMixin.
Lemma card_bool : #|{: bool}| = 2. Proof. by rewrite cardT enumT unlock. Qed.
End BoolFinType.
Section OptionFinType.
Variable T : finType.
Notation some := (@Some _) (only parsing).
Local Notation enumF T := (Finite.enum T).
Definition option_enum := None :: map some (enumF T).
Lemma option_enumP : Finite.axiom option_enum.
Proof. by case => [x|]; rewrite /= count_map (count_pred0, enumP). Qed.
Definition option_finMixin := Eval hnf in FinMixin option_enumP.
Canonical option_finType := Eval hnf in FinType (option T) option_finMixin.
Lemma card_option : #|{: option T}| = #|T|.+1.
Proof. by rewrite !cardT !enumT {1}unlock /= !size_map. Qed.
End OptionFinType.
Maintenant, supposons que j'ai une fonction f de finType à Prop
Variable T: finType.
Variable f: finType -> Prop.
Goal f T. (* Ok *)
Goal f bool. (* Not ok *)
Goal f (option T). (* Not ok *)
Dans les deux derniers cas, je reçois l'erreur suivante:.
The term "bool/option T" has type "Set/Type" while it is expected to have type "finType".
Qu'est-ce que je fais mal ?
Des structures canoniques se déclenchent sur certains problèmes d'unification pour fournir une solution, généralement quand la projection d'un enregistrement est impliquée [voir le manuel] Coq ne détectera pas le problème d'unification particulier, donc le mécanisme canonique t agir. Vous pouvez récupérer l'instance 'finType' associée à bool en utilisant' Goal f [finType of bool] ', voir l'implémentation de cette notation pour plus de détails. – ejgallego