Closed oscbyspro closed 1 month ago
The simple approach seems viable, as far as I can tell:
protocol Recoverable<Value> {
associatedtype Value = Self
var error: Bool { borrowing get }
var value: Value { borrowing get }
}
I could require static functions, but this is also an option:
extension BinaryInteger: Recoverable {
@available(*, deprecated, message: "It always returns: false.")
var error: Bool { false }
@available(*, deprecated, message: "It always returns: self.")
var value: Self { self }
}
Seems great, for the most part, but integer literals need explicit types because of some Recoverable<Value>
.
I suppose it is a kind of boilerplate that could also be solved by a macro. It might be something to think about.
Hm. I might have to go with the fancier approach so that Recoverable/remainder(_:) may return Self, for example.
I'm tempted by the macro approach, because solving a boilerplate problem doesn't seem that valuable on its own. But, I think the protocol approach might still be correct because it is a step towards (#46).
Hm. I wonder how to model IXL/incremented()
:
U32/incremented() -> Fallible<U32>
IXL/incremented() -> IXL // huh?
Fallible<U32>/incremented() -> Fallible<U32>
Fallible<IXL>/incremented() -> Fallible<IXL>
It could also be that this isn't important. It might be simpler to just drop this protocol. Hm.
I want to solve a boilerplate problem. I imagine something like the following would be nice. I already have two approaches in mind. One is proper, but a bit awkward. The other is straightforward, but relies on heroic constant-folding. I'll have to look at the assembly.