(How) can I define partial coercions in Coq? -
i want set coq up, without redefining : notation (and without plugin, , without replacing standard library or redefining constants i'm using---no cheating that), have partial coercion option nat nat, defined on some _. in particular, want
eval compute in 0 : nat. to evaluate 0, , want
check none : nat. to raise error.
the closest i've managed ability 2 :s:
definition dummy {a} (x : option a) := a. definition inverted_option {a} (x : option a) := match x _ => | _ => true end. definition invert_some {a} (x : option a) : inverted_option x := match x v => v | none => end. coercion invert_some : option >-> inverted_option. notation nat' := (inverted_option (a:=nat) (some _)). eval compute in (some 0 : nat') : nat. check (none : nat') : nat. (* term "none" has type "option ?a" while expected have type "nat'". *) however, works when nat' notation, , can't define coercion out of notation. (and trying define coercion inverted_option (some _) nat violated uniform inheritance condition.) thought might able around issue using canonical structures, haven't managed figure out how interleave canonical structure resolution coercion insertion (see can canonical structure resolution interleaved coercion insertion?).
(i ran issue when attempting answer coq: defining subtype.)
Comments
Post a Comment