The monomorphism restriction and monomorphic pattern bindings

Simon Peyton-Jones simonpj at
Thu May 1 03:59:29 EDT 2008

| 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.

Let's also make sure that the spec explicitly includes type signatures.  That is, the above transformation is carried out, and then the individual bindings for the xi are compared with their individual type signatures.


More information about the Haskell-prime mailing list