Improve caching in recursive type comparisons (fixes #1170)

This fix for #1170 improves caching of intermediary results ("maybes") during type relationship checks.