[Haskell-cafe] memorize function with number parameterized types in GHC

Yucheng Zhang yczhang89 at gmail.com
Mon Nov 7 06:51:08 CET 2011

On Mon, Nov 7, 2011 at 9:29 AM, Bin Jin <bjin1990 at gmail.com> wrote:
> Hi
> This method is what I'm looking for. it's a nice general solution, but it
> doesn't solve my problem here.
> I'm using ghc 7.0.3, I tried to cache p2num and montgKeys in the way you
> showed. It seems that ghc doesn't memorize p2num and reject to compile new
> montgKeys.
> I think caching values with dynamic types is complicated in ghc's runtime
> environment. Anyone knows the details?

Adding memorization directly to 'montgKeys' or 'p2num' should be possible,
if you write your own version of MemoTrie dealing with dynamic types.

However, this memorization requires an O(log P) lookup in the trie.
This lookup process will require the whole type structure of P to be
examined, which is of size O(log P).

Yucheng Zhang

More information about the Haskell-Cafe mailing list