1 May 2008 09:59
RE: The monomorphism restriction and monomorphic pattern bindings
| Ok. So I counter-propose that we deal with pattern bindings like this:
|
| The static semantics of a pattern binding are given by the following
| translation. A binding 'p = e' has the same meaning as the set of
| bindings
|
| z = e
| x1 = case z of { p -> x1 }
| ...
| xn = case z of { p -> xn }
|
| where z is fresh, and x1..xn are the variables of the pattern p.
|
| For bang patterns, I think it suffices to say that a bang at the top
| level of p is carried to the binding for z, and then separately define
| what banged variable bindings mean (i.e. add appropriate seqs).
Fair enough. Although there will still be quite a bit of System F plumbing generated, I do agree that answers
my questions about the static semantics of pattern bindings (*provided* we lift the MR). And I agree that
it gives a simple, consistent, and explicable story to the programmer.
The result may or may not do what you want though:
(f, g) = ( (+), (+) )
will generate
f :: (Num a, Num b) => a -> a -> a
which is ambiguous. In general, pattern bindings for overloaded things are probably useless. Perhaps
worth pointing this out in the report.
(Continue reading)
RSS Feed