I'm using Haskell notation for illustration, hopefully it is known widely enough for this to make sense.
In the following fold function the second argument is what I'm calling the identity:
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
It is trivial to fold/reduce over a list of values with certain operations such as addition or multiplication. e.g.
mySum :: (Num a, Foldable t) => t a -> a
mySum = foldr (+) 0 --NB. Works because 0 is the additive identity
myProduct :: (Num a, Foldable t) => t a -> a
myProduct = foldr (*) 1 --NB. Works because 1 is the multiplicative identity
But not all operations have an obvious identity value.
My question is whether there is such thing as a universal identity value, or a function whereby you can find the identity value, or if you can contrive a scheme so that there now is one.
i.e. can you somehow define a z value such that:
foldrUniversal :: Foldable t => (a -> b -> b) -> t a -> b
foldrUniversal f = foldr f z
or could you have a function that determines it:
findIdentity :: (a -> b -> b) -> z --is this possible?
foldrUniversal f = foldr f (findIdentity f)
or can you use some trick so that you always have an identity value even if you don't know what it should be?
(Note that I'm not stuck on a programming problem. I already know about foldr1 in Haskell, or using the head of the list as the identity and then the tail of the list as the list argument. I posted in cs.stackexchange instead of StackOverflow because I'm interested in the theoretical possibilities.)
f
(not its source code), there's not much you can learn just by invoking the functionf
. So therefore I don't think you're going to find what you want. $\endgroup$