This is not possible using parametric polymorphism, due to the following.
Consider the following values:
x = [8] :: [Int] y = [3.0] :: [Double] z = [[]] :: [[Int]]
Obviously, you want your function to work with both x and y , so its type must be null1 :: [a] -> Bool . (Can someone help me make this argument formal? How can I show that this is the unique most specific type without context, unified using [Int] -> Bool and [Double] -> Bool ? Is there a name for this connection between types?)
Now, if you have this type, then null1 z will be equal to null1 x , because they differ only in the values โโof the list items that are abstracted from. (Still not close to formal evidence :()
What you want for z is null2 :: [[a]] -> Bool , which will differ in behavior and thus, for null1 and null2 , the same name will require overloading. (see answer FUZxxl)
Rotorsor
source share