Proposal: Applicative => Monad: Call for consensus

Dan Doel dan.doel at
Mon Jan 17 03:27:18 CET 2011

On Sunday 16 January 2011 7:08:59 pm wren ng thornton wrote:

> Perhaps I missed it, but I don't see anything in that page clarifying
> whether the actual underlying table is shared (i.e., the dictionary is
> just a pointer to a global table) or not (i.e., the dictionary is a
> constructed copy of the table). As far as the surface language is
> concerned the distinction doesn't matter, but as far as people worrying
> about performance considerations due to the size of dictionaries it does.

I can't give a definitive answer, however...

I would be surprised if dictionaries for any given base-case instance weren't 
essentially global. So, Num Int and Monoid [a], for instance, I'd expect to 
just be pointer passing, if that isn't eliminated entirely.

However, there are cases where I'd be surprised if the dictionary is global. 
Polymorphic recursion, for instance, is almost certain to lead to dictionaries 
being constructed per-call at runtime, like:

  foo :: Show a => Integer -> a -> String
  foo 0     x = show x
  foo (n+1) x = foo n (x, x)

This makes use of a dictionary determined by its first parameter, and I 
wouldn't expect GHC to memoize all of them (that seems like a bad performance 

In between, it probably depends on how much information is available 
statically about which dictionaries are actually used.

-- Dan

More information about the Libraries mailing list