Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I agree with @Stephen, let the compiler "do its thing".</p> <p>When you are first starting with a type-inferred language, this will feel unnatural and you'll write extra type annotations, perhaps thinking you need them for readability. You'll get over that soon enough; code with decent variable names has little need for spelling out types everywhere, type annotations are often just excess cruft cluttering your algorithms.</p> <p>I can only think of a couple general detriments to not spelling out the types. First, if you are viewing the source code as a mere text file, it may not be obvious to the reader what the types are. However this is mitigated very largely by the fact that tools like Visual Studio provide hover-tooltips that show the types (e.g. hover your mouse over <code>foo</code> and a tooltip pops up showing the type of <code>foo</code>). The logic for doing this inference is exposed by the compiler source code, and has been easily integrated into other tools, like <a href="http://tomasp.net/articles/fswebsnippets-intro.aspx" rel="nofollow noreferrer">F# web snippets</a>, MonoDevelop, etc. (Someone, please leverage the new Apache license and write the plugins for github, emacs, and gvim :), thanks!) As a result, much of time you're looking at the code, you'll be doing it in an environment/tool where the types are available to be shown on-demand anyway.</p> <p>Second, occasionally it can be hard to debug type errors when there is a lack of type annotations. When you get a weird type inference error you can't figure out, it can be useful to add some explicit annotations to localize the type error. Oftentimes you'll then see some dumb bug in your code, fix it, and then you can remove the needless annotations.</p> <p>Of course, there are a number of places where type annotations are required because type inference can't solve everything. See the links below for some details there. You'll get accustomed to these after a while, and get adept at predicting when you will or won't need an annotation. </p> <p><a href="http://lorgonblog.wordpress.com/2009/10/25/overview-of-type-inference-in-f/" rel="nofollow noreferrer">http://lorgonblog.wordpress.com/2009/10/25/overview-of-type-inference-in-f/</a></p> <p><a href="https://stackoverflow.com/questions/844733/why-cant-fs-type-inference-handle-this">Why can&#39;t F#&#39;s type inference handle this?</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload