4 ms·
Type Inference vs. Static/Dynamic Typing
- joshhart 16y agoPlease keep in mind the type inference systems in Haskell, Ocaml, Scala, etc are much more advanced and useful than C++ 0X or C#
- closure 16y agoDefinitely. I really like Haskell's type inference, but have always been concerned about issues like those raised in: http://www.codecommit.com/blog/scala/universal-type-inference-is-a-bad-thing http://www.codecommit.com/blog/scala/universal-type-inferenc...
- alextgordon 16y agoI find it very difficult to believe that a large source of errors in ML programs are caused by programmers forgetting to annotate type information on top level functions.
- Dn_Ab 16y agoScala does that because ad hoc polymorphism doesnt resolve well with hindley milner type inference. F# also has this limitation and they get some of the way around this with a strict vertical projects file layout. The scope of its type inference is a middle ground between Scala and Ocaml which I think is a nice optimum, you leave most things untyped except the overloads which can't be determined so that the eager generalization you encounter in ocaml is less of a problem there too. The price in project layout is quite steep though but like in all things you train your self around it. Plus with an IDE in Scala (or F#) you can just hover for the types.
- kingkilr 16y agoGood post, one small issue though, "type inference, which you can do in any language", is not really true. Once you get dynamic enough type inference becomes nearly impossible (Cannon, 2005: http://www.google.com/url?sa=t&source=web&cd=4&ved=0CDIQFjAD&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.90.3231%26rep%3Drep1%26type%3Dpdf&ei=0EUdTantA8OWnAeVyYHQDg&usg=AFQjCNGZn2EWRt1-H4FdECqTuqwlMx2zUQ&sig2=5p97iYte4hH4aXyI5KoC_w http://www.google.com/url?sa=t&source=web&cd=4&v...)
- sanxiyn 16y agoYou need to guard your assumptions, but you can do type inference in any language. Take a look at "Declarations as Assertions" section in SBCL manual as well.
- closure 16y agoHere's a link to the relevant section: http://www.sbcl.org/manual/#Declarations-as-Assertions http://www.sbcl.org/manual/#Declarations-as-Assertions
- stcredzero 16y agoYes, but for many languages which are that dynamic, we now have JIT VMs which gather tracing data and can empirically tell us what the types actually are. This is especially true for server apps, which can provide us with large datasets. Also, as noted in a recent article posted to HN, after a certain span of time, most apps in dynamic langs behave as if statically typed. Why don't we use this information? It happens to be move available when it is most valuable. (When a codebase has "matured" and things are moving more towards a "maintenance" mode.)
- kingkilr 16y agoEh? I'm not disputing that at all, I'm a contributor to PyPy, probably the leading python JIT. None of that has anything to do with whether it's semantically possible to do a full type inference on a language like Python.
- illumen 16y agoFull type inference has not been done in python... however partial type inference on python has been done. The article is talking about partial type inference, and most implementations of type inference I've seen do partial type inference.
- stcredzero 16y agoI'm not disputing either. I'm just pointing out that the dynamic language communities are neglecting a really valuable resource.
- blasdel 16y agoIf you want to understand the fundamentals, read the classic: http://web.archive.org/web/20080822101209/http://www.pphsg.org/cdsmith/types.html http://web.archive.org/web/20080822101209/http://www.pphsg.o...