[Haskell-cafe] monomorphism restriction

Jonathan Cast jonathanccast at fastmail.fm
Wed Jun 11 23:48:56 EDT 2008


On Wed, 2008-06-11 at 20:24 -0700, Don Stewart wrote:
> page:
> > Definition of f:
> >    f = foldr (+) 0
> > Types:
> >    0 :: (Num t) => t
> >    foldr (+) 0 :: Num a => [a] -> a
> >    f :: [Integer] -> Integer
> > 
> > Please remind me, again, of the advantages of f being something different 
> > from the formula defining it.
> 
> Overloaded 'constants' take a dictionary as an argument, so while you
> think the value might be computed only once, it make actually be
> recomputed each time. This can be a killer performance penalty for
> overloaded numeric constants.
> 
> Of course, disabling this is pretty simple.

This doesn't apply to f, though --- it has a function type, so the user
presumably already knows it won't be subject to updating, no?
Distinguishing functions from variables by the form of declaration,
rather than the type, seems somewhat questionable to me.

jcc




More information about the Haskell-Cafe mailing list