Easy, in F always prefer to let the compiler "do its thing". The folks who wrote its powerful type inference system would be saddened otherwise In all seriousness, in C# I know there is (or was? ) a debate about when or when not to use var for infered variable types.
But I believe the concerns there about the lack of clarity stemmed from a community which was unfamiliar with terse, strongly typed languages and feared var was some kind of dynamic voodoo not to be trusted. But what we have now in C#, and many times over in F#, is the best of all worlds. Strong, automatic typing.
And "variables" are only the tip of the ice-burg. The real amazement comes with F#'s inference of function type signatures. There was a while there where I believed this was over-the-top, and that writing out the full signature would be clearer.
Man, you get over that fast.
Easy, in F#, always prefer to let the compiler "do its thing". The folks who wrote its powerful type inference system would be saddened otherwise. In all seriousness, in C# I know there is (or was?) a debate about when or when not to use var for infered variable types.
But I believe the concerns there about the lack of clarity stemmed from a community which was unfamiliar with terse, strongly typed languages and feared var was some kind of dynamic voodoo not to be trusted. But what we have now in C#, and many times over in F#, is the best of all worlds. Strong, automatic typing.
And "variables" are only the tip of the ice-burg. The real amazement comes with F#'s inference of function type signatures. There was a while there where I believed this was over-the-top, and that writing out the full signature would be clearer.
Man, you get over that fast.
I agree with @Stephen, let the compiler "do its thing". 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.
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 foo and a tooltip pops up showing the type of foo).
The logic for doing this inference is exposed by the compiler source code, and has been easily integrated into other tools, like F# web snippets, 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. 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. 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. lorgonblog.wordpress.com/2009/10/25/over... Why can't F#'s type inference handle this?
Haha, the dreaded value restriction :) – Benjol Nov 8 '10 at 7:13.
In this particular case it looks quite easy to infer the dt's type. The signature of Option. So why F# can't do this inference?
Tomas mentions in his book that F# infers types by going from the first to the last argument and that's why the order of arguments matters. And that's why F# can't infer the types in the first example. But why F# can't behave like C#, i.e.
Try to infer types incrementally starting with what is known? In most cases F# is much more powerful when speaking about type inference... that't why I'm confused a bit.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.