This coercion caused difficult-to-diagnose bugs sometimes. Because there are some situations where converting a string to a name should be done by parsing the string, and others where it should not, an explicit choice seems better here. --------- Co-authored-by: Mac Malone <tydeu@hatpress.net>
15 lines
431 B
Text
15 lines
431 B
Text
import Lean
|
||
open Lean
|
||
|
||
local macro "ofNat_class" Class:ident n:num : command =>
|
||
let field := Lean.mkIdent <| .mkSimple Class.getId.eraseMacroScopes.getString!.toLower
|
||
`(class $Class:ident.{u} (α : Type u) where
|
||
$field:ident : α
|
||
|
||
instance {α} [$Class α] : OfNat α (nat_lit $n) where
|
||
ofNat := ‹$Class α›.1
|
||
|
||
instance {α} [OfNat α (nat_lit $n)] : $Class α where
|
||
$field:ident := $n)
|
||
|
||
ofNat_class Zero 0
|