Mysterious type-checking failure in connection with type equality constraint