If a function has a case that will result in returning the input as-is, is there anything to be gained by using a point-free id
for that case?
Example:
-- First way, use some symbol as wildcard
myFunc :: Int -> SomeData -> SomeData
myFunc 0 _ = _
myFunc ...
-- Second way, point-free `id`. Is this more efficient?
myFunc :: Int -> SomeData -> SomeData
myFunc 0 = id
myFunc ...
One standard function where I thought this might be used is drop
since drop 0
is effectively id
. But if you look at the source code, it is not point free (there is drop 0 xs = xs
... you have to scroll down a little to see the definition; look for drop (I# n#) ls
). I suspect it can't matter much if drop
doesn't make use of it.
Edit: Actually it looks like equations with differing numbers of arguments is disallowed by the case-expansion method for translating multiple-equation function definitions.
So if you opted for this route, you'd have to make sure all the remaining equations for the function are also definable in the same point-free style -- which is highly unlikely for most functions.