John Hughes wrote:

> Some suggest that it is enough for compilers to issue a warning when using
> call-by-name. I disagree strongly.

I agree with Johns objection to the compiler warning solution, so here is another
suggestion:

The monomorphism restriction makes sure that certain values are computed at most
once by restricting them to be used at only one type. Couldn't the same be
achieved by

   * getting rid the monomorphism restriction, i.e., let all definitions to be
     overloaded by default,
   * add the language implementation requirement that overloaded values should be
     computed at most once for each instance they are used at.

Advantages of this solution:

   * It solves the problem. Since all definitions can be overloaded, definitions
     that today need the eta expansion fix, or the type signature fix, will work
     without the fix.
   * We have semantic backwards compatibility. For those programs that depend on
     the monomorphism restriction for efficiency, this solution should give the
     same efficiency.
   * We have syntactic backwards compatibility. No syntactic change is needed.
   * We get more consistent uses of type signatures. Type signatures are only
     used to restrict types, not to make them more general. (This means for
     example that a type signature that was added for documentation purposes can
     always be commented out if types change a lot during program development...)

One question then is how feasible this is to implement. But isn't this what you
get in implementations that resolve overloading at compile time rather than by
passing dictionaries at run time? Hasn't this been tried already (In GHC? In
Hugs?) and found to be feasible? (The reason it might not be feasible is that you
can get a code explosion, possibly an infinite one.)

Have I missed something fundamental that prevents this solution from working?

--
Thomas Hallgren



Reply via email to