Repository navigation
Remove specification of Prelude from Chapter 9 - #115
BinderDavid wants to merge 3 commits into
Conversation
| These behavioural specifications are given in the form of documentation comments which provide a reference implementation. | ||
| Many of these reference implementations are written with clarity rather than efficiency in mind, | ||
| and it is not required that the specification be implemented as shown. |
There was a problem hiding this comment.
If possible, it would be good to spell out how closely implementations are expected to conform to the reference implementation. What changes for efficiency are permitted? Non-strict semantics makes this a bit tricky, because often "as defined as possible" (avoiding unnecessary strictness) may not be quite the same as "most efficient in normal use". Presumably the implementation of a function is required to at least agree with the reference function on all inputs in normal form, but is it allowed to change strictness properties? What about memory usage?
There was a problem hiding this comment.
Agreed, I will add this to the text.
My opinion is that the behavioural specification should not put any restrictions on time or memory behaviour. The reason is simply that the Haskell report currently doesn't specify a call-by-need evaluation strategy, and it therefore isn't possible to do time or space reasoning based solely on the spec.
I think implementations should implement functions with the same strictness behaviour, and the GHC user guide follows this interpretation. In the bugs and infelicities section it says, for example:
splitAt semantics
Data.List.splitAt is more strict than specified in the Report. Specifically, the Report specifies that
splitAt n xs = (take n xs, drop n xs)
which implies that
splitAt undefined undefined = (undefined, undefined)
but GHC’s implementation is strict in its first argument, so
splitAt undefined [] = undefined
of reference implementation. Implementations are bound by strictness of reference implementation.
| Many of these reference implementations are written with clarity rather than efficiency in mind, | ||
| and it is not required that the specification be implemented as shown. | ||
|
|
||
| Implementations must have the same strictness behaviour as the reference implementation. |
There was a problem hiding this comment.
Continuing on what @adamgundry commented above -- this certainly sounds somewhat dangerous (as with splitAt above). It might be the case that this clause would imply standardizing inefficient implementations.
What if we allow the implementations to be less strict than the report (thus "less dangerous"), and make sure that everything specified in the library report is at least as strict as in current compilers?
There was a problem hiding this comment.
(in the meantime I'd go for temporarily removing the clause so that this can get voted in ;) )
There was a problem hiding this comment.
There's certainly a tension here, although splitAt is not a very compelling example, because it's not actually clear GHC's version is more efficient than the Report version (#92 (comment)).
My view is that:
- A library that aims to be a compliant implementation of the library report should agree on strictness with the report.
- A compiler that aims to be a compliant implementation of the language report may support other base libraries than the one specified in the library report, and ideally should allow users to choose their base libraries, with at least one option being the report standard library.
In practice, I expect this to mean that:
baseis not completely report-compliant (e.g.splitAt, other strictness changes, and because it exposes additional modules) but its divergences are documented as properties ofbaserather than GHC;- we can provide a
haskell2010library that is more closely report-compliant and is more stable/limited thanbase; and - users of GHC have the option to depend on
baseorhaskell2010.
This means base is free to diverge from the report on strictness (or otherwise) where its maintainers believe that to be a good idea, but users who want to nail down the libraries completely can still do so.
Section 9 is currently the location where the public interface and the behaviour of all entities of the
Preludemodule are documented. Section 9 has the following major issues that this PR addresses:Preludeis defined in terms of three other modulesPreludeIO,PreludeTextandPreludeListas an organizing principle. This organization dates back to Haskell98 which only had a flat module namespace, and does not correspond to how functions and types exposed by the Prelude are nowadays grouped. Modern Haskell andbaseuse modulesControl.Monad.IO,Data.List,Text.Read,Text.Showetc. instead. In Expose additional modules from the standard library #111 we already took the steps to adapt to this new organizational principle by exposing these modules.PseudoHaskell. This makes it impossible to check the specification for consistency by running it through a compiler when we expand or modify it.Preludehave to apply every change twice: Once to the code in chapter 9, and once in the modules in thestdlibdirectory. This is extremely error prone and not fun to do :)The solution that this PR proposes is to repurpose chapter 9 to describe the relationship between the language report and the library report, which is provided as a separate document in the revised report. This entails the following changes:
Prelude.In order to not make this PR too complicated I have left several TODOs which we have to tackle afterwards.
stdlibhave to be added back later. This should look similar in content to what RestoreData.Arrayspecification #40 does.baseto be conforming to the library report.