Polymorphic \"constants\", like 5 :: Num a => a, aren\'t really constants but functions of a dictionary argument. Hence, if you define
primes ::
One could add Typeable constraint to n and use a different memoization table for every ground type n. You probably would need to exploit Dynamic and cast a lot for this, which is suboptimal. It also feels a bit hackish, too.
In a dependently typed language, of course, one can model a map (n : Num) -> [n] which would not require the castss from Dynamic. Maybe something like that can be simulated exploiting GADTs and some kind of reification machinery.