Im writing a function for add edge in a graph that takes a function as parameter, I’d like to ensure that function return a specified type E. How do I do it?
Why would you like to do this? It is something that is tricky or impossible to ensure using the type system, unless you use some kind of wrapper.
Generally I would suggest that you either check the type of arguments, or simply convert to the desired type. This is generally a low-cost operation and would make your code more generic.