[GHC Users] Dictionary sharing

Jonas Almström Duregård jonas.duregard at chalmers.se
Fri Jun 29 13:25:42 CEST 2012


Hi,

Is there a way to ensure that functions in a class instance are
treated as top level definitions and not re-evaluated?

For instance if I have this:
>>>
class C a where
  list :: [a]

instance List a => List [a] where
  list = permutations list
<<<
How can I ensure that list :: [[X]] is evaluated at most once for any
type X (throughout my program)?

I assume this is potentially harmful, since list can never be garbage
collected and there may exist an unbounded number of X's.

I currently have a solution that uses Typeable to memoise the result
of the function based on its type. Is there an easier way?

Regards,
Jonas



More information about the Glasgow-haskell-users mailing list