Type classes for creating memoized functions