Memoization should not ingore type parameters. Fixes #1417.