Following code runs into problems when using different types of Generators. A 
Generator is just a proc with no parameters that returns some type of value.

[https://play.nim-lang.org/#ix=2cRz](https://play.nim-lang.org/#ix=2cRz)
    
    
    import macros, sugar
    
    type Generator[T] = () -> T
    
    proc gen1(): float =
      result = 42.0
    
    proc gen2(): int =
      result = 66
    
    proc gen3(): string =
      result = "Hello"
    
    macro genTuple1[T](gen1: Generator[T]): untyped =
      result = newStmtList()
    
    macro genTuple2[T, U](gen1: Generator[T], gen2: Generator[U]): untyped =
      result = newStmtList()
    
    macro genTuple3[T, U, V](gen1: Generator[T], gen2: Generator[U], gen3: 
Generator[V]): untyped =
      result = newStmtList()
    
    # ... and so on and so forth
    
    # Would love to have s.th like that but obviously not valid syntax
    macro genTuple(args: varargs[Generator[auto]]): untyped =
      result = newStmtList()
    
    genTuple1(gen1) # works
    genTuple2(gen1, gen2)
    #[
    Error: type mismatch: got <proc (): float{.noSideEffect, gcsafe, locks: 
0.}, proc (): int{.noSideEffect, gcsafe, locks: 0.}>
    but expected one of:
    macro genTuple2[T, U](gen1: Generator[T]; gen2: Generator[U]): untyped
      first type mismatch at position: 2
      required type for gen2: Generator[genTuple2.U]
      but expression 'gen2' is of type: proc (): int{.noSideEffect, gcsafe, 
locks: 0.}
    ]#
    
    # When all Generators are of the same type, e.g. Generator[int] then no 
problem
    genTuple2(gen2, gen2)
    
    # same type mismatch error message
    genTuple3(gen1, gen2, gen3)
    
    
    Run

I'm doing something wrong here. But don't know really what. Maybe generics are 
not really allowed with macros?

Reply via email to