When programming Haskell, I use the definition of the behavior of a function based on the input it receives, and not just its signature. For instance:
f :: Int -> Int
f 2 = 4
f 3 = 9
f 4 = 16
f x = 0
With Java, I know that I can overload a function as:
public String f (String s) {
System.out.println(s);
}
public String fb (Integer i) {
System.out.println("Sorry, not a string!");
}
However, I was wondering if I can overload a function based on its exact input, and not just on its signature. (To avoid case / if branches)
Sort of
public String f ("a") {
}
public String f ("not a") {
}
Cheers, Dario
source
share