Changes between Version 3 and Version 4 of MonomorphicPatternBindings

Show
Ignore:
Timestamp:
08/11/06 07:11:39 (7 years ago)
Comment:

--

Unmodified
Removed
Modified
• MonomorphicPatternBindings

v3 v4
11== Make pattern bindings monomorphic ==
22
3 Proposal: make all pattern bindings completely monomorphic (regardless of type signatures)
3=== The Proposal ===
44
5I propose that we '''make all pattern bindings completely monomorphic (regardless of type signatures)'''.  As a result, the expression
6{{{
7  let (p,q) = (\x -> x, True) in (p True, p 'c')
8}}}
9would fail to typecheck, because it requires p to be polymorphic.  The program would be rejected even if p had a type signature:
10{{{
11  let { p :: a -> a
12      ; (p,q) = (\x -> x, True)
13  } in (p True, p 'c')
14}}}
15We 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:
16{{{
17  (x,y) = e    -- Pattern binding
18  [x]   = e    -- Pattern binding
19  (x)   = e    -- Pattern binding
20  x@y   = e    -- Pattern binding
21  ~x    = e    -- Pattern binding
22
23  x     = e    -- NOT a pattern binding
24}}}
25This rule is simple and easy to remember.
26
27Notice 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.
28
29Another way to say it is this: only function bindings are generalised, where a function binding has the form
30  f p1 ... pn = e
31
32where n>=0.   The n=0 case is a bare variable.
33
34=== Discussion ===
535At the moment you can say
636{{{