|
|
## Make pattern bindings monomorphic
|
|
|
|
|
|
### The Proposal
|
|
|
|
|
|
Proposal: make all pattern bindings completely monomorphic (regardless of type signatures)
|
|
|
|
|
|
I propose that we **make all pattern bindings completely monomorphic (regardless of type signatures)**. As a result, the expression
|
|
|
|
|
|
```wiki
|
|
|
let (p,q) = (\x -> x, True) in (p True, p 'c')
|
|
|
```
|
|
|
|
|
|
|
|
|
would fail to typecheck, because it requires p to be polymorphic. The program would be rejected even if p had a type signature:
|
|
|
|
|
|
```wiki
|
|
|
let { p :: a -> a
|
|
|
; (p,q) = (\x -> x, True)
|
|
|
} in (p True, p 'c')
|
|
|
```
|
|
|
|
|
|
|
|
|
We need to be precise about what a "pattern binding" is. Definition: **a pattern binding has the form *pat*=*rhs*, where *pat* is not simply a variable. Examples:
|
|
|
**
|
|
|
|
|
|
```wiki
|
|
|
(x,y) = e -- Pattern binding
|
|
|
[x] = e -- Pattern binding
|
|
|
(x) = e -- Pattern binding
|
|
|
x@y = e -- Pattern binding
|
|
|
~x = e -- Pattern binding
|
|
|
|
|
|
x = e -- NOT a pattern binding
|
|
|
```
|
|
|
|
|
|
|
|
|
This rule is simple and easy to remember.
|
|
|
|
|
|
|
|
|
Notice that enclosing the variable in parens, thus (x)=e, makes it a pattern binding, and therfore forces it to be monomorphic. So this is a way to get the monomorphic form of binding that John Hughes has, at times, argued for.
|
|
|
|
|
|
|
|
|
Another way to say it is this: only function bindings are generalised, where a function binding has the form
|
|
|
|
|
|
>
|
|
|
> f p1 … pn = e
|
|
|
|
|
|
|
|
|
where n≥0. The n=0 case is a bare variable.
|
|
|
|
|
|
### Discussion
|
|
|
|
|
|
|
|
|
At the moment you can say
|
... | ... | |