leanprover-community / quote4

Intuitive, type-safe expression quotations for Lean 4.
Apache License 2.0
75 stars 12 forks source link

Add type variables to unquote context, if they implement `ToExpr` #10

Closed alexkeizer closed 1 year ago

alexkeizer commented 1 year ago

If a variable α : Type u implements ToExpr, then add it to the context available inside q(...) and Q(...), with the quoted value of ToExpr.toTypeExpr.

This resolves #9, enabling us to write, e.g.,

import Qq
open Qq Lean

def listToExpr {α : Type} [ToExpr α] : List α → Q(List $α)
  | []       => q([])
  | a :: as  => q($a :: $(listToExpr as))