Changes between Initial Version and Version 1 of SpecifyPatternBindingSemantics

May 14, 2008 2:55:10 PM (9 years ago)
Simon Marlow

summarising discussion from the mailing list


  • SpecifyPatternBindingSemantics

    v1 v1  
     1= Specify the static semantics of pattern bindings =
     3Currently the Haskell 98 report doesn't specify clearly the static semantics of pattern bindings.  Tricky cases arise when considering whether a pattern binding can define polymorphic values (see also MonomorphicPatternBindings), or when the binding is overloaded.  In Haskell 98, overloaded pattern bindings cannot declare polymorphic values, due to the monomorphism restriction, but if we were to lift the monomorphism restriction we have to consider carefully what an overloaded polymorphic pattern binding would mean.
     5The proposal is to define the static semantics by the following
     6translation.  A binding `p = e` has the same meaning as the set of
     10    z = e
     11    x1 = case z of { p -> x1 }
     12    ...
     13    xn = case z of { p -> xn }
     16where `z` is fresh, and `x1...xn` are the variables of the pattern p.
     18Note that this specification addresses one of the main concerns of MonomorphicPatternBindings, namely that it is not clear what (overloaded, polymorphic) pattern bindings should mean.
     20== Ambiguity ==
     22It is easy to end up with ambiguity when using overloaded pattern bindings.  The example from the Haskell 98 report which is used to justify the monomorphism restriction is
     25  [(n,s)] = reads t
     28which according to the above translation will give us
     31n :: (Read t) => t
     32s :: (Read t) => String
     35there is no way to refer to `s`, and a type signature for `s` cannot be given.  Neither can this cannot be resolved by giving a type signature for `n` (unless perhaps we have ScopedTypeVariables with type signatures on pattern variables and we put a signature on `n` in the pattern).  We may want to mention this issue in the report.
     37== Other issues ==
     39 * We should make sure that the specification also takes into account any type signatures for the pattern-bound variables.
     41== Binding terminology ==
     43Additionally, we propose to clarify the terminology for bindings.  The Haskell 98 report uses the term "simple pattern binding" inconsistently.  The new terminology is:
     45 * variable binding: any binding of the form `x = e`
     46 * pattern binding: any binding of the form `p = e` where `p` is not a variable
     47 * function binding: any binding of the form `f = e` where `n > 0`