I’ve ran into multiple scenarios now where I’d like to pass a function as an argument to another function, but I want to make sure it conforms to a certain type signature.
function dosomething(times::Int,doit::Function) for i=1:times doit(i) end end
What I’d like to do in the above example is restrict
doit() to any
Function that takes a single
Int argument. Obviously, I could just document that in the usage, and “hope” that it works out. But, I think it would be cleaner to be able to specify the type signature I require somehow.
I can’t see a straightforward way to do this. Am I missing something? Would this be a useful feature to add to the language? I’ve enjoyed a similar feature, “
Protocols” in Objective-C.