| 54 | | Replace [http://haskell.org/onlinereport/decls.html#sect4.5.1 section 4.5.1] with: |
| | 54 | Replace the body of [http://haskell.org/onlinereport/decls.html#sect4.5.1 section 4.5.1] '''Dependency analysis''' |
| | 55 | |
| | 56 | In general the static semantics are given by the normal Hindley-Milner inference rules. A ''dependency analysis transformation'' is first performed to increase polymorphism. Two variables bound by value declarations are in the same ''declaration group'' if either |
| | 57 | |
| | 58 | 1) they are bound by the same pattern binding, or |
| | 59 | |
| | 60 | 2) their bindings are mutually recursive (perhaps via some other declarations that are also part of the group). |
| | 61 | |
| | 62 | Application of the following rules causes each {{{let}}} or {{{where}}} construct (including the {{{where}}} defining the top level bindings in a module) to bind only the variables of a single declaration group, thus capturing the required dependency analysis: (A similar transformation is described in Peyton Jones' book [10].) |
| | 63 | |
| | 64 | 1) The order of declarations in where/let constructs is irrelevant. |
| | 65 | |
| | 66 | 2) {{{let}}} {''d,,1,,''; ''d,,2,,''} {{{in}}} ''e'' = {{{let}}} {''d,,1,,''} {{{in}}} (let {''d,,2,,''} {{{in}}} ''e'') |
| | 67 | (when no identifier bound in ''d,,2,,'' appears free in ''d,,1,,'') |
| | 68 | |
| | 69 | with: |
| 76 | | * The first paragraph of [http://haskell.org/onlinereport/decls.html#sect4.5.2 section 4.5.2] isn't quite right: |
| 77 | | * It deals with {{{let}}}'s consisting of a single binding, instead of declaration groups. Note that we can no longer assume that a {{{let}}} has a single declaration group. |
| 78 | | * It does not seem to deal with functions, non-trivial patterns or recursion. |
| | 91 | |
| | 92 | The first paragraph of [http://haskell.org/onlinereport/decls.html#sect4.5.2 section 4.5.2] isn't quite right: |
| | 93 | |
| | 94 | The Hindley-Milner type system assigns types to a {{{let}}}-expression in two stages. First, the right-hand side of the declaration is typed, giving a type with no universal quantification. Second, all type variables that occur in this type are universally quantified unless they are associated with bound variables in the type environment; this is called ''generalization''. Finally, the body of the {{{let}}}-expression is typed. |
| | 95 | |
| | 96 | * It deals with {{{let}}}'s consisting of a single binding, instead of declaration groups. Note that we can no longer assume that a {{{let}}} has a single declaration group. |
| | 97 | * It does not seem to deal with functions, non-trivial patterns or recursion. |