math-comp/mcb

Possible Type in Section 6.10 Ad-hoc polymorphism

czhang03 opened this issue · 0 comments

Here is the code from the book

Inductive phantom (T : Type) (p : T) := Phantom.

Definition set_of (T : eqType) (_ : phantom Type (Equality.sort T)) := seq T.
Notation "{ 'set' T }" := (set_of _ (Phantom Type T))
    (at level 0, format "{ ’set’  T }") : type_scope.

Since the book recommends the setting Set Implicit Arguments. which will make many arguments here implicit, therefore this code will not work

Here is a version that write out all the argument explicitly, which will pass the type checking

Inductive phantom (T : Type) (p : T) := Phantom.

Definition set_of (T : eqType) (_ : @phantom Type (Equality.sort T)) := seq T.
Notation "{ 'set' T }" := (@set_of _ (@Phantom Type T))
    (at level 0, format "{ 'set' T }") : type_scope.

(*Some examples*)
Check {set nat}.
Check [:: 1]: {set nat}.