It's easy to overload your own functions like so:
void testVal(loc l) {
println("LOC <l>");
}
void testVal(value v) {
println("VAL <v>");
}
such that testVal(|tmp:///|) will call the first method. I wish to do the same to IO::println:
void println(loc l) {
IO::println("my custom println function");
}
to serve for debug purposes. println(|tmp:///|) should now print "my custom println function". Is it possible to do this? For me this code still defaults to the IO implementation.
Function overloading works by non-deterministic selection. So if the patterns of
testValorprintlnoverlap, then there is no way to know which one is chosen first.In fact in your example,
loc loverlaps withvalue vso the priority between the two alternatives is undefined.To fix this, one of the alternatives must get a more precise pattern (e.g. change
value vtonum vto distinguish it fromloc l, or you can put thedefaultmodifier before the function:If you want to override an existing function that does not have the
defaultmodifier, I am afraid you are out of luck. You can't change the IO module to add thedefault. So to work around this issue you can wrap the IO::println function in your own function: