[Haskell-beginners] Lambda Functions

Brent Yorgey byorgey at seas.upenn.edu
Fri Feb 27 12:31:22 EST 2009


The only disadvantage is that some things you might expect to be
constants will actually get recomputed every time they are used. For
example, suppose you define

  foo = very expensive computation involving a bunch of numbers

You might think that foo will get computed just once, the first time
it is needed.  However, if foo ends up with a polymorphic type, like,
say

  foo :: Num a => a

then it is not actually a constant, but a function which takes a Num
dictionary (i.e. a record of the Num methods) as an argument.  So it
will be recomputed every time it is used, since it might have
different values for different types.

Now, you might wonder why this is such a big deal.  The answer is: it
isn't.  I have the MR automatically turned off in my .ghci file, and
I've never missed it.  Furthermore, the monomorphism restriction will
be removed in the next version of the Haskell language standard.

-Brent

On Fri, Feb 27, 2009 at 08:41:36AM +0000, Matt R wrote:
> On 26/02/2009, Andrew Wagner <wagner.andrew at gmail.com> wrote:
> > Excellent list. It seems like every time I hear about a problem with the
> > MMR, I go "wow, how come I never ran across that? oh yeah, because I write
> > type signatures..."
> 
> Certainly. Still, it seems relatively easy to bump into it when
> tinkering on ghci.
> 
> Out of interest, what are the disadvantages to blanket turning off the
> restriction?
> 
> -- Matt
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


More information about the Beginners mailing list