Type checking for memoization