I'd like to check that anyelem and anyarray have the same element type. but anyelem is obtained from PG_FUNCTION_ARGS as a Datum. How can I make such a check?
As I know, it's implicitly checked during query analyze stage. You don't have to implement your own check inside function implementation.