... | ... | @@ -45,6 +45,13 @@ |
|
|
|
|
|
|
|
|
|
|
|
Haskell 98 specifies that type inference be performed in dependency order to increase polymorphism. However most Haskell implementations use a more liberal rule (proposed by Mark Jones).
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
|
|
|
|
In Haskell 98, a group of bindings is sorted into strongly-connected components, and then type-checked in dependency order ([ H98 s4.5.1](http://haskell.org/onlinereport/decls.html#sect4.5.1)). As each dependency group is type-checked, any binders of the group that have an explicit type signature are put in the type environment with the specified polymorphic type, and all others are monomorphic until the group is generalized ([ H98 s4.5.2](http://haskell.org/onlinereport/decls.html#sect4.5.2)).
|
|
|
|
|
|
|
... | ... | @@ -83,41 +90,74 @@ and then go on to successfully check the type signature of `zig`. |
|
|
Dependency groups are smaller, and more programs type-check.
|
|
|
|
|
|
|
|
|
## Description
|
|
|
## References
|
|
|
|
|
|
|
|
|
- [ Dependency Analysis](http://haskell.org/onlinereport/decls.html#sect4.5.1) in the Haskell 98 Report
|
|
|
- [ Typing Haskell in Haskell](http://www.cse.ogi.edu/~mpj/thih/), Mark Jones, Haskell Workshop 1999.
|
|
|
|
|
|
## Report Delta
|
|
|
|
|
|
|
|
|
|
|
|
Modify the definition of dependency group in the above section to
|
|
|
Replace [ section 4.5.1](http://haskell.org/onlinereport/decls.html#sect4.5.1) with:
|
|
|
|
|
|
|
|
|
>
|
|
|
>
|
|
|
> Two variables bound by value declarations are in the same declaration group if either
|
|
|
> In general the static semantics are given by the normal Hindley-Milner inference rules. A dependency analysis transformation is first performed to increase polymorphism.
|
|
|
>
|
|
|
>
|
|
|
|
|
|
>
|
|
|
>
|
|
|
> 1) they are bound by the same pattern binding, or
|
|
|
> A variable *x* *depends* on a variable *y* (bound in the same list of declarations) if
|
|
|
>
|
|
|
>
|
|
|
|
|
|
>
|
|
|
> >
|
|
|
> >
|
|
|
> > 1) they are bound by the same pattern binding, or
|
|
|
> >
|
|
|
> >
|
|
|
>
|
|
|
> 2) their bindings are mutually recursive (perhaps via some other declarations that are also part of the group), *ignoring uses of variables that have an explicit type signature*
|
|
|
|
|
|
>
|
|
|
> >
|
|
|
> >
|
|
|
> > 2) *y* has no type signature and the binding defining *x* contains an occurrence of *y*, or
|
|
|
> >
|
|
|
> >
|
|
|
>
|
|
|
|
|
|
>
|
|
|
> >
|
|
|
> >
|
|
|
> > 3) *x* depends on a variable *z* that depends on *y*.
|
|
|
> >
|
|
|
> >
|
|
|
>
|
|
|
|
|
|
The semi-formal rules in the rest of the section would have to go: it would no longer be possible to make binding groups explicit with a source-to-source transformation.
|
|
|
>
|
|
|
>
|
|
|
> A *declaration group* is a minimal set of bindings of mutually dependent variables. Hindley-Milner type inference is applied to each declaration group in dependency order.
|
|
|
>
|
|
|
>
|
|
|
|
|
|
|
|
|
## References
|
|
|
Notes:
|
|
|
|
|
|
|
|
|
- [ Dependency Analysis](http://haskell.org/onlinereport/decls.html#sect4.5.1) in the Haskell 98 Report
|
|
|
- [ Typing Haskell in Haskell](http://www.cse.ogi.edu/~mpj/thih/), Mark Jones, Haskell Workshop 1999.
|
|
|
- also tightens up the original wording, which didn't mention that the declarations had to be in the same list and also defined *declaration group* but not dependency.
|
|
|
- the transformations formerly listed in this section are no longer always possible.
|
|
|
|
|
|
## Other issues
|
|
|
|
|
|
## Report Delta
|
|
|
|
|
|
- The Report sometimes speaks of "value bindings", "value declarations" or "function and pattern bindings". It might be best to standardize on "value bindings".
|
|
|
- Similarly "declaration groups" might more precisely be called "binding groups", since other kinds of declaration are not involved.
|
|
|
- The first paragraph of [ section 4.5.2](http://haskell.org/onlinereport/decls.html#sect4.5.2) isn't quite right:
|
|
|
|
|
|
- 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.
|
|
|
- It does not seem to deal with functions, non-trivial patterns or recursion. |