[Haskell-cafe] monomorphism restriction

Don Stewart dons at galois.com
Wed Jun 11 23:24:02 EDT 2008


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.

-- Don


More information about the Haskell-Cafe mailing list