i didn't know about `{.borrow:'.'.}` thanks for that. unfortunately it doesn't work through an alias: type Bar[T,R]{.borrow:`.`.} = distinct Foo[T] Baz = Bar[int,float] ## Error: only a distinct type can borrow '.' Run
tbh, this is why i dont muck around with borrow, every time i try it, i hit bug/edge case almost immediately. in my case, i've discovered i'm fine; `Foo[T]` is a union, so i need accessor funcs to do the right thing at compiletime, anyway. Your explanation that you cant dispatch on extra parameters in an alias makes a lot of sense. sounds like i'll have to get a handle on distinct. Something like this works, but i dunno how robust it is: type Foo[T] = object x:T Bar[T,R]{.borrow:`.`.} = distinct Foo[T] template makeBar(t,r:typedesc):type = type Internal{.borrow:`.`.} = distinct Bar[t,r] converter toBar(b:Internal):Bar[t,r] = Bar[t,r](b) converter toBar(b:var Internal): var Bar[t,r] = Bar[t,r](b) Internal type Barr = makeBar(int,float) Bazz = makeBar(int,float) proc foo(f:Barr):string = "Barr" proc foo(f:Bazz):string = "Bazz" proc qux(f:Bar):string = $f.typeof.T & $f.typeof.R proc plugh(f:var Bar,i:int) = f.x = i var b:Barr c:Bazz echo typeof(b),typeof(c) #Internal'gensym0,Internal'gensym1 #which could be better i suppose echo b.x,c.x #0 0 echo b.qux,c.qux #int,float int,float echo b.foo,c.foo #Barr Bazz Run it has the limitation that you can't create a type in an internal scope (converters can only be created at top scope) and the var converter doesn't work type X = makeBar(int,float) var x:X x.plugh(5) #expression x is immutable, not var converter sudoToBar(x:var X):var Bar[int,float] = Bar[int,float](x) x.plugh(5) #still no Run