4 ms·
Python ecosystem is getting more verbose and less ergonomic than Haskell while still not being able to reach even the minimum level of type safety of the latter
by ghostwriter 4y ago
Python ecosystem is getting more verbose and less ergonomic than Haskell while still not being able to reach even the minimum level of type safety of the latter (i.e. a default compiler mode without extensions like GADTs, type families and so on). At the same time Haskell ecosystem is getting more ergonomic and "pythonic". Consider these two complete and fully typed minimal programs. Why do they keep saying that Python is great for small scripts?
import Data.Foldable (for_)
main = do
let words = ["Hello", "World"]
for_ words (\word -> print word)
vs
from typing import Iterable
def main() -> None:
words: Iterable[str] = ["Hello", "World"]
for word in words:
print(word)
if __name__ == '__main__':
main()
- animal_spirits 4y agoTyping in small scripts is pointless. The type annotations are only useful for large codebases
- ghostwriter 4y agoVarious automation/pipelining scripts benefit greatly from typing, as it at least provides a level of assurance that data of proper shape is passed to relevant functions at all times. It helps especially when the automation scripts parse and extract and concatenate yaml portions from larger configs. I wouldn't want to write manual unit tests just to ensure shapes' validity.
- MapleWalnut 4y agoYour Python example has unnecessary type annotations. Python type checkers like mypy and Pylance can infer the type of `words` automatically. def main() -> None: words = ["Hello", "World"] for word in words: print(word) if __name__ == '__main__': main()
- ghostwriter 4y agoYes and no. That particular example can indeed be type-checked without extra annotations (unless I want to indicate that the use-case of the variable is actually immutable). But consider I slightly modify the script: def main() -> None: words = [] for word in (words + ["Hello"]): print(word) if __name__ == '__main__': main() MyPy rejects to infer the type of the iterable. Here's an equivalent Haskell version that does infer the type without manual annotations: import Data.Foldable (for_) main = do let words = [] for_ (words ++ ["Hello"]) (\word -> print word)
- tejinderss 4y agotypescript can infer it too: function main() { let words = []; for (const word of [...words, 'Hello']) { console.log(word); } }
- Zababa 4y ago> Why do they keep saying that Python is great for small scripts? I think comparing hello world is a bit unfair. A script may have something like file manipulation, regex, http requests.