TODO: Support memoization of generic functions