4 ms·
Wouldn't the return value of the previous function in the chain make it obvious? E.g. in Python you can have def foo() -> Generator def bar(x: Iterab
by nerdponx 8y ago
Wouldn't the return value of the previous function in the chain make it obvious?
E.g. in Python you can have
def foo() -> Generator
def bar(x: Iterable) -> Sequence
def baz(y: Sequence) -> List
lst = baz(bar(foo()))
It's obvious to an experienced Python user (and to a static type checker) what is lazy here. All you need now is a compiler to enforce it.
- lmm 8y agoYou don't necessarily know which functions are going to be chained together though. If I write (my Python's a bit rusty): def f(x): return map(someOtherFunction, map(someFunction, x)) how can I know whether someOtherFunction interferes with someFunction if they run at the same time? The only way to know whether the maps are strict or lazy is knowing what x is, but x might come from some a different file or a different project even, so there's no way to know whether this function only works (and is only expected to work) for strict x or not. Actually even knowing what x is isn't enough, because even if x is strict, f can end up being called in a lazy way if I later do: (y for x in someGeneratorThatGeneratesLists for y in f(x))
- nerdponx 8y agoThat's my point about a static type system. You don't have that problem if types are known at compile time. I agree that it's a nuisance in Python as-is (but I still like it overall).
- lmm 8y ago> That's my point about a static type system. You don't have that problem if types are known at compile time. You probably do though, because people would write f to be polymorphic and then only test with strict collections.