5 ms·
Show HN: A Python with Hindley-Milner-like type annotations, compiling to C
- keenerd 11y agoPackaged: https://aur4.archlinux.org/packages/hermetic-git/ https://aur4.archlinux.org/packages/hermetic-git/
- LukeHoersten 11y agoReally impressive work!
- jaytaylor 11y agoAnd that generated C code is quite amusing to boot!
- strictfp 11y agoA typed and fast Python with concurrency is something I've wanted for the longest time. I really hope that this will take off.
- dagw 11y agoHave you looked at cython? It's (optionally) typed, fast (with only a little bit of effort extra effort over writing normal python), makes the GIL optional (for a reasonable subset of cases) and, most importantly, stable and ready to use today (so no waiting).
- Demiurge 11y agoYes, Cython is exactly that, typed python.
- kevin_thibedeau 11y ago+1 for cython. The only criticism I could make is that the real speedups come when you can avoid using PyObjects which means the easiest way to employ it is in the inner loops of numeric code where it truly is phenomenal. Complex data structures have to be boiled into C-style structs to get any significant speedup with them although there is still a base level performance boost from having everything compiled into cpython API calls.
- dagw 11y agoComplex data structures have to be boiled into C-style structs to get any significant speedup I've never really played with it, but cython does have mappings between python builtin types and STL containers, as well as letting you create C++ classes using cython syntax that you can inherit from and access in python.
- Fede_V 11y agoYes, that's correct, but if you are using semi-complex objects, then you have to invoke the python interpreter and lose most of the advantage of going to Cython in the first place. Even for things like ints, floats, etc - if you want to see a significant speed up, you have to convert them into c ints and floats.
- david-given 11y agoHave you tried Nim? The syntax is Python-inspired rather than Python-like, but it seems to combine a lot of the nice features of dynamic languages with the rigour of a static language. https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programm... http://nim-lang.org/ http://nim-lang.org/ Haven't played with it myself, as I'm still waiting for a compiler to show up in Debian, but I plan to.
- agumonkey 11y agoPython is the new lisp.
- __john 11y agoNow if we could just get an emacs written in Python =).
- Animats 11y agoThere have been other typed Python variants. RPython, in which PyPy was written, is sort of one. Shed Skin tried to do it entirely via type inference, which is really hard across functions. It's clear now that you want at least enough type inference in a language that LHS types of assignments and variable creations are inferred when possible. When you have that, as in Go, Rust, and even C++ to some extent, most of the declarations are in function definitions. There, you want them for documentation purposes anyway.
- keypusher 11y agoMyPy is a pretty good typed Python variant. I believe the "optional type annotations" PEP used their style. http://mypy-lang.org/ http://mypy-lang.org/
- nly 11y ago> even C++ to some extent C++ can also infer return types, the following is a valid C++14 function definition auto foo() { auto curry = [](auto x) { return [=](auto y) { return x + y; }; }; auto add42 = curry(42); return add42(58); } which incidentally gets compiled to this: 0000000000000000 <foo()>: 0: mov $0x64,%eax 5: retq
- lorenzhs 11y agoVery cool idea, I like it. But I can't really get much to compile yet -- while loops do not work, nor does range(). Anyway, quite impressive!
- alehander42 11y agoYep, it's still more like a prototype, so not everything is supported(but I'll add support for all basic constructs soon, stay tuned)
- lorenzhs 11y agoNice. I wanted to find out how well it performs (with a simple summing task) but I gave up before I had managed to loop over a range. I'll check back in a week or two ;)
- alehander42 11y agoIt does support `for ... in range(start, end)` and `while` now. You can check out two summing examples in the examples dir too. It typically gives ~ 6-7x speedup on my machine.
- deleted 11y ago[deleted]
- jjangsangy 11y agoA Python 3 based library that compiles to C?! > "yeah, you need a shower now, doncha" I saw that there is a requirements.txt file, but it's blank. This project amazes me, knowing it exists gives me motivation to get better That is all...
- evacchi 11y agoCorrect me if I'm wrong but IIRC HM is not applicable with class-based inheritance. How do you (plan to) deal with this? BTW I really like the idea of a typed, compilable Python, keep it up!
- alehander42 11y agoWell yeah, but I wanted to experiment with the language type system(it started from HM, but it can go anywhere). Classes/records are not implemented yet, but I can imagine that we have two cases: <object_with_known_exact_class>.<method> then we'll just convert that to a normal function invocation in c(because we'll be able to detect the exact ancestor which defines the method and the method) <an_instance_of_some_class>.<method> if we only know that an object is an instance of a class, we can wrap the invocation in an inline switch on the type field of the object.(instances would map to C structs).
- bkeroack 11y agoThe value-add here is that it compiles to C and therefore the type enforcement is done at compile time. If you are OK with interpreted Python and runtime checking you can use https://github.com/prechelt/typecheck-decorator/ https://github.com/prechelt/typecheck-decorator/
- alehander42 11y agoThat looks cool! It's pretty different though, it's more like a "design by contract" tool. I have a similar one, more Python2 style dsl (it supports also function overloading through a kind of pattern matching) https://github.com/alehander42/py-matchete https://github.com/alehander42/py-matchete
- dochtman 11y agoThose who like this might also like my language project, Runa: A Python-like systems programming language. This means that the design borrows as much from Python as makes sense in the context of a statically-typed, compiled language, and tries to apply the Zen of Python to everything else. The most important design goals for Runa are developer ergonomics and performance. The compiler is written in Python and targets LLVM IR; there's no run-time. More information can be found on the project website. https://github.com/djc/runa/ https://github.com/djc/runa/