3 ms·
I think the key ingredient you're looking for is mutability. If you take advantage of the ability to implicitly modify state, your declared interfaces reduce in
by Twisol 2y ago
I think the key ingredient you're looking for is mutability. If you take advantage of the ability to implicitly modify state, your declared interfaces reduce in size because you don't need to model the threading of state through the interface. Since mutability means that your method signatures are less restrictive then they appear to be, it makes sense that this research (focusing on dependent types, and especially on dependently-typed proofs) would prefer a setting without implicit mutability. (Mutation is orthogonal to OOP vs. FP, anyway -- you can have pure OOP interfaces and also mutable FP interfaces.)
The Java stream interface also has a lot of methods that can technically be implemented in terms of other methods on the interface, but are present so that implementers can provide more efficient implementations depending on the capabilities of their model of streams. It makes sense that the present research would only consider the bare essentials of streams, and not things that could be layered on top at the cost of some optimization opportunities.
As a Java programmer, the essence of an OOP stream seems to be captured by the following interface:
interface Stream<T> {
T next();
}
If we make mutation explicit, this evolves into:
interface Stream<T> {
Pair<T, Stream<T>> next();
}
And then we can split this into two methods, providing each of the two components of the original `Pair`:
interface Stream<T> {
T head();
Stream<T> tail();
}
This is exactly what the paper shows on page 2, up to syntactic differences (like explicit type parameters to the methods).