You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vsintegration/ProjectTemplates/TutorialProject/Template/Tutorial.fsx
+107-6Lines changed: 107 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@
36
36
/// To learn more, see: https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/xml-documentation
37
37
38
38
39
-
// Open namespaces using the 'open'directive.
39
+
// Open namespaces using the 'open'keyword.
40
40
//
41
41
// To learn more, see: https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/import-declarations-the-open-keyword
42
42
openSystem
@@ -64,10 +64,32 @@ module IntegersAndNumbers =
64
64
/// This is a list of all tuples containing all the numbers from 0 to 99 and their squares.
65
65
letsampleTableOfSquares=[for iin0..99->(i, i*i)]
66
66
67
-
// The next line prints a list that includes tuples, using%A for generic printing.
67
+
// The next line prints a list that includes tuples, using'%A' for generic printing.
68
68
printfn"The table of squares from 0 to 99 is:\n%A" sampleTableOfSquares
69
69
70
70
71
+
/// Values in F# are immutable by default (save for Arrays). They cannot be changed
72
+
/// in the course of a program's execution unless explicitly marked as mutable.
73
+
///
74
+
/// To learn more, see: https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/values/index#why-immutable
75
+
moduleImmutability=
76
+
77
+
/// Binding a value to a name via 'let' makes it immutable.
78
+
///
79
+
/// The second line of code fails to compile because 'number' is immutable and bound.
80
+
/// Re-defining 'number' to be a different value is not allowed in F#.
81
+
letnumber=2
82
+
// let number = 3
83
+
84
+
/// A mutable binding. This is required to be able to mutate the value of 'otherNumber'.
85
+
let mutableotherNumber=2
86
+
87
+
// When mutating a value, use '<-' to assign a new value.
88
+
//
89
+
// Note that '=' is not the same as this. '=' is used to test equality.
90
+
otherNumber<- otherNumber+1
91
+
92
+
71
93
/// Much of F# programming consists of defining functions that transform input data to produce
72
94
/// useful results.
73
95
///
@@ -94,7 +116,7 @@ module BasicFunctions =
94
116
95
117
/// Conditionals use if/then/elid/elif/else.
96
118
///
97
-
/// Note that F# uses whitespace indentation-aware syntax, similar to languages like Python or Ruby.
119
+
/// Note that F# uses whitespace indentation-aware syntax, similar to languages like Python.
98
120
letsampleFunction3 x=
99
121
if x<100.0then
100
122
2.0*x*x- x/5.0+3.0
@@ -192,6 +214,78 @@ module Tuples =
192
214
printfn"Struct Tuple:%A\nReference tuple made from the Struct Tuple:%A" sampleStructTuple(sampleStructTuple|> convertFromStructTuple)
193
215
194
216
217
+
/// The F# pipe operators ('|>', '<|', etc.) and F# composition operators ('>>', '<<')
218
+
/// are used extensively when processing data. These operators are themselves functions
219
+
/// which make use of Partial Application.
220
+
///
221
+
/// To learn more about these operators, see: https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/functions/#function-composition-and-pipelining
222
+
/// To learn more about Partial Application, see: https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/functions/#partial-application-of-arguments
223
+
modulePipelinesAndComposition=
224
+
225
+
/// Squares a value.
226
+
letsquare x= x* x
227
+
228
+
/// Adds 1 to a value.
229
+
letaddOne x= x+1
230
+
231
+
/// Tests if an integer value is odd via modulo.
232
+
letisOdd x= x%2<>0
233
+
234
+
/// A list of 5 numbers. More on lists later.
235
+
letnumbers=[1;2;3;4;5]
236
+
237
+
/// Given a list of integers, it filters out the even numbers,
238
+
/// squares the resulting odds, and adds 1 to the squared odds.
239
+
letsquareOddValuesAndAddOne values=
240
+
letodds= List.filter isOdd values
241
+
letsquares= List.map square odds
242
+
letresult= List.map addOne squares
243
+
result
244
+
245
+
/// A shorter way to write 'squareOddValuesAndAddOne' is to nest each
246
+
/// sub-result into the function calls themselves.
247
+
///
248
+
/// This makes the function much shorter, but it's difficult to see the