6 ms·
Using Type inference[1] on a language could be able to figure out types in most situations. [1] https://en.wikipedia.org/wiki/Type_inference https://en.wikiped
by zitterbewegung 7y ago
Using Type inference[1] on a language could be able to figure out types in most situations.
[1] https://en.wikipedia.org/wiki/Type_inference https://en.wikipedia.org/wiki/Type_inference
- amelius 7y agoYes, some programming languages take this approach but I don't think that prototyping is as easy in such languages as it is in a dynamically typed language (e.g. Haskell vs Python).
- rwmj 7y agoWhen writing OCaml, if I'm unsure of the type I set the type to some impossible value, compile it, and the compiler tells me what the type really is.
- hnra 7y agoI Haskell you simply put a "_" in the annotation and the compiler suggests the correct type.
- dllthomas 7y agoYou can also do this with values, asking "what goes here?" - it's great.
- andrepd 7y agoAlternatively, merlin can tell you the type of the expression under your cursor, besides also flagging type mismatches like your situation.
- yakshaving_jgt 7y agoIn my experience (currently writing Haskell professionally, previously writing Ruby professionally) prototyping is easier in Haskell. How many systems have you prototyped in Haskell?
- dllthomas 7y ago> prototyping is easier in Haskell That's very much my experience, as well. Assuming - and it's a very big assumption - that your use case has equivalent library support.
- zitterbewegung 7y agoWhat would be neat is if you could take a Python program and run type inference on the program and it would output a type annotated version of the code.
- duckerude 7y agoI don't have experience with it, but pytype can do that: https://github.com/google/pytype https://github.com/google/pytype After typechecking it leaves provisional stubs in .pytype/pyi/, and it has a tool to merge them into the original code. mypy has stubgen: https://mypy.readthedocs.io/en/latest/stubgen.html https://mypy.readthedocs.io/en/latest/stubgen.html As far as I know it's less powerful since mypy isn't really built for unannotated code and pytype is.
- hopia 7y agoProductivity can be really subjective. Those that are used to modeling the problem domain with the type system find that their most productive approach, even with prototyping.
- dllthomas 7y agoRight, and the type system is such a big help in refactoring - especially in small projects - that you don't have to be all that right in your first N cuts at the model. You can write code and find out where you're wrong, and fix it fast.
- pwm 7y agoIt’s even more help in larger projects :) The dividends of type-checher aid refactoring really start paying off once the project is above a a certain size/age.
- dllthomas 7y agoYeah, I think I was unclear. Given a need to refactor, it's a bigger help on a bigger refactor. But a large refactor on a large project is still a pain. By the time you get there, you still want your model stable and/or flexible enough that you don't need to do that much. On a small enough project, every refactor is easy enough that you can lean into it. Make a bunch of assumptions you're not confident about, setting up the types so you're sure you'll know what needs fixing when they're wrong. Then you test those assumptions as you write - and run - more code.
- azhenley 7y agoYes, but "Type inference has usability problems". http://web.eecs.utk.edu/~azh/blog/typeinference.html http://web.eecs.utk.edu/~azh/blog/typeinference.html
- leshow 7y agoI'm curious why you quote this like it's a fact when it's an opinion. The understanding of type inference used as the basis for making the argument in that blog post is superficial. Type inference doesn't just allow you to leave off type information from variables. A good inference engine will infer the most generic type for variables (and functions!), it's a discovery that you can query the compiler for in order to do type driven development. A full rebuttal of this blog post would take much longer, but suffice to say inference does the exact opposite of what they are claiming; it increases readability and usability.
- azhenley 7y agoI quoted the title of my blog post. Do you have any evidence for your claim that it increases readability or usability? A few human-subjects studies from different labs have recently been ran on this and the findings mostly agree with my opinions. Papers forthcoming.
- pwm 7y agoI don’t agree with readibility (there are pros and cons, ie. terser code vs. implicit types) but, at least in Haskell, it improves usability by inferring the most generic type to your expression.
- leshow 7y agoAgree on what? "Type inference" is a broad feature, feel free to post the resources. edit: In Haskell it goes beyond just locally inferring variables, it enables a new type of development with typed holes that feels more like a back and forth conversation with the compiler. I don't see how "I can leave the types off my C# variables" has anything to do with that.
- 7y ago