Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
William Sørensen committed Aug 14, 2024
1 parent da244f2 commit afd8df3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 9 additions & 3 deletions Qpf/Macro/Data/Constructors.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ partial def countConstructorArgs : Syntax → Nat
| Syntax.node _ ``Term.arrow #[_, _, tail] => 1 + (countConstructorArgs tail)
| _ => 0

def mkConstructorsWithNameAndType (view : DataView) (shape : Name) (nameGen : CtorView → Ident) (ty : Term) := do
/--
Add definitions for constructors
that are generic across two input types shape and name.
Additionally we allow the user to control how names are generated.
-/
def mkConstructorsWithNameAndType (view : DataView) (shape : Name)
(nameGen : CtorView → Name) (ty : Term) : CommandElabM Unit := do
for ctor in view.ctors do
trace[QPF] "mkConstructors\n{ctor.declName} : {ctor.type?}"
let n_args := (ctor.type?.map countConstructorArgs).getD 0
Expand All @@ -38,7 +44,7 @@ def mkConstructorsWithNameAndType (view : DataView) (shape : Name) (nameGen : Ct
name := `matchPattern
}]
}
let declId := nameGen ctor
let declId := mkIdent $ nameGen ctor

let cmd ← `(
$(quote modifiers):declModifiers
Expand All @@ -54,7 +60,7 @@ def mkConstructorsWithNameAndType (view : DataView) (shape : Name) (nameGen : Ct
-/
def mkConstructors (view : DataView) (shape : Name) : CommandElabM Unit := do
let explicit ← view.getExplicitExpectedType
let nameGen := (mkIdent <| ·.declName.replacePrefix (←getCurrNamespace) .anonymous)
let nameGen := (·.declName.replacePrefix (←getCurrNamespace) .anonymous)

mkConstructorsWithNameAndType view shape nameGen explicit

Expand Down
14 changes: 8 additions & 6 deletions Qpf/Macro/Data/View.lean
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ def DataView.addDeclNameSuffix (view : DataView) (suffix : String) : DataView
{ view with declName, declId, shortDeclName }


/-- Returns the fully applied form of the type to be defined -/
def DataView.getExpectedTypeWithId (view : DataView) (id : Ident) : Term
:= Syntax.mkApp id (
(Macro.getBinderIdents view.binders.getArgs false)
)
/--
Returns the fully applied form of the type to be defined.
The `name` parameter allows the user to control what the const at the bottom of the type is.
This lets the user get types that have the same parameters such as the DeepThunk types.
-/
def DataView.getExpectedTypeWithName (view : DataView) (name : Name) : Term :=
Macro.getBinderIdents view.binders.getArgs false |> Syntax.mkApp (mkIdent name)

/-- Returns the fully applied form of the type to be defined -/
def DataView.getExpectedType (view : DataView) : Term
:= view.getExpectedTypeWithId (mkIdent view.shortDeclName)
:= view.getExpectedTypeWithName view.shortDeclName

/-- Returns the fully applied, explicit (`@`) form of the type to be defined -/
def DataView.getExplicitExpectedType (view : DataView) : CommandElabM Term
Expand Down

0 comments on commit afd8df3

Please sign in to comment.