Factoid: F# uses type inference. The programmer does not need to declare types - the compiler deduces types during compilation.
Length 17 Snippet
0let a=1
A function that returns zeroWe can now define (the compiler infers the type to integer)values. Commonly used asValues in F# are immutable by default, that is the final statement to returnreason we avoid the program exit codeuse of the term "variable".
The snippet defines an immutable value "a" that contains a 1 (integer).
Length 26 Snippet
;;2.**8.
I could've used an empty string (""
) asNow we can use the snippet. That would create aPower function that returns an empty string, but it is the same concept as the length 1 snippet. :D
Instead,Note that I pickedcould not call the empty statement in F# Interactive (FSI). FSI is a REPL tool that allows you to declare, construct and otherwise experimentPower function before with your code in an interactive mannerarguments "2" and it is very useful. In my opinion"8", because [the arguments] would be considered integers. The decimal points make the compiler to infer a floating point number. This snippet correctly returns a 256.0 ;;
is used more frequently than empty strings(float) value.
You must append double semicolons (;;
) at the end of your statementsFloats in FSI to indicate the end of inputF# are double precision.
Length 35 Snippet
nan[|0|]
ThreeAt five characters unlocks many basic arithmetic operations, finally, we can define an array with one element (1+2as mentioned before, 9*9 and so on). But I pickedthe compiler infers the type to nanint[]
). It is
Not to be confused with a shortcut function that simply returns System.Double.NaNlist. An empty list is defined simply by the square brackets like this: []
Useful to compareThe element separator, in both lists and arrays, is the semicolon (or match, as we'll later see;
) the result of a function.as in [| 1;2;3 |]
Length 53 Snippet
[|0|]nan
At fiveThree characters, finally, we can define an array with one element unlocks many basic arithmetic operations (as mentioned before1+2, the compiler infers the type to9*9 and so on). But I picked int[]nan
). It is a shortcut function that simply returns System.Double.NaN.
NotUseful to be confused withcompare (or match) the result of a listfunction. An
Length 2 Snippet
;;
I could've used an empty list is defined simply by the square brackets like this:string ([]""
) as the snippet. That would create a function that returns an empty string, but it is the same concept as the length 1 snippet.
The element separatorInstead, I picked the empty statement in both lists and arraysF# Interactive (FSI). FSI is a REPL tool that allows you to declare, construct and otherwise experiment with your code in an interactive manner and it is very useful. In my opinion, the semicolon (;;;
) as in is used more frequently than empty strings.
You must append double semicolons ([| 1;2;3 |];;
) at the end of your statements in FSI to indicate the end of input.
Length 61 Snippet
2.**8.0
Now we can use the PowerA function. :D
Note that I could not call the Power function before with arguments "2" and "8", because [the arguments] would be integers. The decimal points make the compiler to infer a floating point number. This snippet correctly returns a 256.0zero (floatthe compiler infers the type to integer) value. Commonly used as the final statement to return the program exit code.
Floats inFactoid: F# are double precision, byuses type inference. The programmer does not need to declare types - the waycompiler deduces types during compilation.