So, now I ended up with this (thanks Jasper):
template skel(T: untyped): untyped =
let fn = proc(): T =
echo "I am fn"
fn
proc gen(T: NimNode): NimNode =
getAst skel(T)
macro foo(T: typedesc): untyped =
gen(T)
discard foo(int)()
Run
I know there are very good reasons why things work the way they do, but the
above is not obvious, trivial or simple. There is a thing called generics, but
you can't use it for macros, and all macro arguments are NimNodes, except for
typedescs. The generics/Nim-idiomatic way to do this would be something like
this:
template skel[T](): untyped =
let fn = proc(): T =
echo "I am fn"
fn
proc gen[T](): NimNode =
getAst skel[T]()
macro foo[T](): untyped =
gen[T]()
discard foo[int]()()
Run
Maybe one day in Nim 2.0 :)