[Haskell-cafe] monomorphism restriction

Rafal Kolanski xs at xaph.net
Sat Jun 14 03:19:19 EDT 2008


Ryan Ingram wrote:
> sumns 0 = 0
> sumns x = sumns (x-1) + n
> 
> Without the monomorphism restriction, computing n is a function call;
> it is evaluated each time it is asked for.

I'm relatively new to Haskell, and since this topic already came up, I
was wondering if anyone could explain to me how this ties into implicit
parameters which "escape" from their respective functions?

For instance, if I just state:
maxLength = maxLengthParameter ?config
without providing a type signature and then use it, I get warned that
?config "escapes" from maxLength and that I should provide a type
signature or turn off the monomorphism restriction.

I find implicit parameters are a really nice way to pass a configuration
to a whole tree of functions (in this case an LZSS compressor) without
having to explicitly add it as a parameter to every single one of the
functions.

What are the performance implications of turning off the restriction and
allowing implicit parameters to "escape"? Are there general performance
implications of implicit parameters I am not aware of?

Yours Sincerely,

Rafal Kolanski.




More information about the Haskell-Cafe mailing list