Skip to content

Possible Type in Section 6.10 Ad-hoc polymorphism #123

@czhang03

Description

@czhang03

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}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions