Skip to main content
Post Made Community Wiki by Dennis
added 699 characters in body
Source Link
Mike Rod
  • 393
  • 2
  • 3

Length 9 Snippet

(10, "Z")

Tuples! a Tuple is defined as a comma separated collection of values. While Lists (and Arrays) gravitate towards the concept of a Set, Tuples are more like a data structure that groups related values.

The snippet defines a 2-tuple. One value is integer, the other string. F# annotates the type as: int * string

Tuples are considered ad hoc types, so they are passed as a single argument, can be a return type and so on.

F# has two built in functions to help with tuples: fst and snd that return the first or second element of a Tuple respectively. Tuples are not limited to just two elements, though.

Length 8 Snippet

Ranges also workThe range syntax is the same for lists and arrays.

Length 8 Snippet

Ranges also work for arrays.

Length 9 Snippet

(10, "Z")

Tuples! a Tuple is defined as a comma separated collection of values. While Lists (and Arrays) gravitate towards the concept of a Set, Tuples are more like a data structure that groups related values.

The snippet defines a 2-tuple. One value is integer, the other string. F# annotates the type as: int * string

Tuples are considered ad hoc types, so they are passed as a single argument, can be a return type and so on.

F# has two built in functions to help with tuples: fst and snd that return the first or second element of a Tuple respectively. Tuples are not limited to just two elements, though.

Length 8 Snippet

The range syntax is the same for lists and arrays.

added 309 characters in body
Source Link
Mike Rod
  • 393
  • 2
  • 3

Length 8 Snippet

[-9..10]

F# allows to define ranges of sequential values. This snippet generates a list of 20 integer elements, -9 and 10 inclusive.

You can define stepping values, for example [0..10..50] will yield a list of 6 elements: [0; 10; 20; 30; 40; 50].

Ranges also work for arrays.

Length 7 Snippet

Now we can use the Power function. :D

At five characters, finally, we can define an array with one element (as mentioned before, the compiler infers the type to int[]).

Length 7 Snippet

Now we can use the Power function. :D

At five characters, finally, we can define an array with one element (as mentioned before, the compiler infers the type to int[]).

Length 8 Snippet

[-9..10]

F# allows to define ranges of sequential values. This snippet generates a list of 20 integer elements, -9 and 10 inclusive.

You can define stepping values, for example [0..10..50] will yield a list of 6 elements: [0; 10; 20; 30; 40; 50].

Ranges also work for arrays.

Length 7 Snippet

Now we can use the Power function.

At five characters, we can define an array with one element (as mentioned before, the compiler infers the type to int[]).

added 224 characters in body
Source Link
Mike Rod
  • 393
  • 2
  • 3

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.

Factoid: F# uses type inference. The programmer does not need to declare types - the compiler deduces types during compilation.

Length 1 Snippet

0

A function that returns zero (the compiler infers the type to integer). Commonly used as the final statement to return the program exit code.

Length 2 Snippet

;;

I could've used an empty 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.

Instead, I picked the empty statement in F# 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 ;; is used more frequently than empty strings.

You must append double semicolons (;;) at the end of your statements in FSI to indicate the end of input.

Length 3 Snippet

nan

Three characters unlocks many basic arithmetic operations (1+2, 9*9 and so on). But I picked nan. It is a shortcut function that simply returns System.Double.NaN.

Useful to compare (or match, as we'll later see) the result of a function.

Length 5 Snippet

[|0|]

At five characters, finally, we can define an array with one element (as mentioned before, the compiler infers the type to int[]).

Not to be confused with a list. An empty list is defined simply by the square brackets like this: []

The element separator, in both lists and arrays, is the semicolon (;) as in [| 1;2;3 |]

Length 6 Snippet

2.**8.

Now we can use the Power 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.0 (float) value.

Floats in F# are double precision, by the way.

Length 7 Snippet

let a=1

We can now define values. Values in F# are immutable by default, that is the reason we avoid the use of the term "variable".

The snippet defines an immutable value "a" that contains a 1 (integer).

Length 6 Snippet

2.**8.

Now we can use the Power function. :D

Note that I could not call the Power function before with arguments "2" and "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 (float) value.

Floats in F# are double precision.

Length 5 Snippet

[|0|]

At five characters, finally, we can define an array with one element (as mentioned before, the compiler infers the type to int[]).

Not to be confused with a list. An empty list is defined simply by the square brackets like this: []

The element separator, in both lists and arrays, is the semicolon (;) as in [| 1;2;3 |]

Length 3 Snippet

nan

Three characters unlocks many basic arithmetic operations (1+2, 9*9 and so on). But I picked nan. It is a shortcut function that simply returns System.Double.NaN.

Useful to compare (or match) the result of a function.

Length 2 Snippet

;;

I could've used an empty 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.

Instead, I picked the empty statement in F# 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 ;; is used more frequently than empty strings.

You must append double semicolons (;;) at the end of your statements in FSI to indicate the end of input.

Length 1 Snippet

0

A function that returns zero (the compiler infers the type to integer). Commonly used as the final statement to return the program exit code.

Factoid: F# uses type inference. The programmer does not need to declare types - the compiler deduces types during compilation.

added 496 characters in body
Source Link
Mike Rod
  • 393
  • 2
  • 3
Loading
added 929 characters in body
Source Link
Mike Rod
  • 393
  • 2
  • 3
Loading
added 599 characters in body
Source Link
Mike Rod
  • 393
  • 2
  • 3
Loading
added 180 characters in body
Source Link
Mike Rod
  • 393
  • 2
  • 3
Loading
Source Link
Mike Rod
  • 393
  • 2
  • 3
Loading