Hi! As far as I understood there are no generic overloads.
What I want to achieve:
type
Action* = proc(){.nimcall.}
Action*[T] = proc(arg: T){.nimcall.}
The reason is simple: I don't want to write down each time proc(){.nimcall.}, this is odd, I just want to treat those pointers as actions ( slightly similar to C# )
How I can achieve that?
There is no type overload but this may work (though void is a bit tricky):
type
Action*[T] = when T is void: proc() {.nimcall.}
else: proc(arg: T){.nimcall.}
But the idiomatic way to solve that would be with push/pop
{.push nimcall.} # Add nimcall pragma to all proc
proc foo() = discard
proc bar[T](arg: T) = discard
{.pop.} # Stop adding the nimcall pragma
proc baz[T](arg: T) = discard
thanks, today I've learned about push and pop pragmas XD I need types though, but your examples are useful anyway :)
Can the type overloading be added to Nim at some point or it's something no-no and won't be considered?
I don't think so.
First of all, no other language has type overloading.
Second, generics and the type system in general are already the most complex part of Nim internals (or are within top 3). The accumulated cruft over the years inside is mind-boggling and I wouldn't add another complex project on top while we have so many corner cases in:
oh, maybe we are speaking about different things. I don't know how it works on the C# side but I can achieve this: https://i.gyazo.com/00fb604855c4e9e7b5a9e8d409567f6b.png
but I can't reproduce that in Nim
What if I want to define a type of tuple with that kind of actions?
#@Actions
type
Action* = proc(){.nimcall.}
ActionT*[T] = proc(arg: T){.nimcall.}
#@Objects
type
ObjectEvents* = tuple[start: Action, tick: ActionT[float], stop: Action]