The dreaded M-R
rjmh at cs.chalmers.se
Thu Jan 26 11:07:17 EST 2006
Simon Marlow wrote:
>On 26 January 2006 09:59, John Hughes wrote:
>>The solution I favour is simply to use *different syntax* for the two
>>forms of binding, so that a definition is monomorphic, and computed
>>at most once, if it uses the monomorphic binding operator, and
>>polymorphic/overloaded, computed at each use, if it uses the other.
>>Whether it's a function definition or not is irrelevant, as is whether
>>or not it carries a type signature.
>>The trick is finding good syntax. I suggest = for bind-by-name, and
>>:= for bind-by-need.
>The reasoning for the proposal makes complete sense to me, but I don't
>feel the proposed solution strikes the right balance. The MR is a
>subtle point that we don't want to have to burden newcomers to the
>language with, but having two forms of binding is a fundamental part of
>the language design that would surely crop up early on the Haskell
>learning curve. John - how do you envisage teaching this?
I don't think it's hard. I would just teach students to define functions
and "variables" with :=. I tell my students to write type signatures at
anyway, so they don't risk being bitten by the M-R anyway. Beginning
just do what you tell them, and they already think of function and variable
definitions as different. Learning a different syntax for one of them
be a problem.
Once they've mastered basic programming and start getting interested in
like overloading, then you have to explain how the M-R works. I'd much
explain =/:= than try to teach them how you know whether a definition is
shared or not right now.
>I wonder if there's an alternative solution along these lines:
> - We use ParialTypeSignatures to make bindings monomorphic:
> x :: _
> x = (+1)
> - we make it a static error for a variable bound by a simple pattern
> binding ("x = e") to be overloaded, unless a type signature is
> The error message would explain the problem, and how to fix it.
> Alternatively, we make it a strong warning.
>It seems to me that the partial type signatures extension provides a lot
>of bang for the buck - it gives us a way out of the MR in addition to
>partial type signatures.
I don't like this. Once students start dropping type signatures (which
pretty soon for local variables in where-clauses), they would sometimes--
unpredictably as far as they're concerned--get an error message telling them
they must put one back in again, but it's enough to write x :: _. Can
explaining to an average student in the first year why they MUST put in a
type signature, but it doesn't need to include a type???
Don't underestimate the difficulties many students already face. At this
they're not even completely sure what the difference is between a type and a
value, let alone a type and a class! Understanding the effect of the
or absence of a type signature is beyond most students until much, much
If we replace or revise the M-R, the replacement should be very, very
The M-R in its present form is a clever, and not terribly complicated
--but complicated enough to have caused no end of trouble over the years.
Let's not be clever, let's be straightforward and explicit: two binding
More information about the Haskell-prime