-
Notifications
You must be signed in to change notification settings - Fork 0
/
F_Sharp_Anki.txt
478 lines (478 loc) · 70 KB
/
F_Sharp_Anki.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
What is a keyword that associates an identifier with a value or function <code>let</code>
What is the <code>let</code> value binding syntax? <code>let identifier-or-pattern [: type] = expression<br>body-expression</code>
What is the <code>let</code> function binding syntax? <code>let identifier parameter-list [:return-type] =<div> expression</div><div>body-expression</div></code>
What is the scope of <code>let</code>? Limited to the portion of the containing scope (function, module, file or class) after the binding appears
If you separate the <code>let</code> expression from the identifier what must you do to the expression? Indent each line
What is the following:<br /><br><code>let i, j, k = (1, 2, 3)</code> Pattern that contains names.
What is the <code>let body-expression</code>? The expression in which names are used.
Where may a <code>let</code> appear? <code>module</code> level, definition of a class type or in local scopes.
Where must a <code>let</code> have a <i>body-expression</i>? Local scopes and functions, not at <code>module</code> level or in a <code>class</code> type.
Where are bound names usable? After the point of definition but not at any point before the <code>let</code> binding appears.
How do function <code>let</code> bindings differ from value bindings? Function bindings include the function name, parameter list and return type.
What is 'a' in: <br /><br><code>let function a = a + 1</code> Name of the parameter
What is 'function' in:<br /><br><code>let function a = a + 1</code> Name of the function.
What kind of parameter is this: <br /><br><code>let function2 (a, b) = a + b</code> This parameter is a pattern, specifically a <code>tuple</code> pattern.
What does a <code>let binding expression</code> evaluate to? The value of the last expression.
What is being applied to the parameter: <br /><br><code>let function1 (a: int) = a + 1</code> Type annotation
What does the second 'int' define: <br /><br><code>let function1 (a: int) : int = a + 1</code> The return type of the function.
Where can a <code>let</code> binding not appear? A <code>let</code> binding may not appear in a structure or record type.
What is required of a class to contain a <code>let</code> binding? A primary constructor ex. <br /><br><code>type MyClass(a) = ...</code>
What is the default visibility for a <code>let</code> binding contained within a class? <code>private</code>
What is the scope of a <code>let</code> within a type? Scope is limited to the type (and likely also all previous scope rules apply as well).
Where may <code>let</code> bindings contain explicit type parameters? At the <code>module</code> level, in a type or in a computation expression.
What can be applied to top-level <code>let</code> bindings of a <code>module</code>? Attributes: ex. <br /><br><code>[<Obsolete>]<div>let function1 x y = x + y</div></code>
When is a <code>let</code>-bound value in a <code>module</code> accessible to clients? When the <code>module</code> is accessible.
When are let-bindings in a class accessible to clients? Never, they are <code>private</code> to the class.
How do clients refer to let-bound values in a module they have access to? By using the fully-qualified name: ModuleName.FunctionName.
How do clients refer to <code>let</code>-bound values in an accessible <code>module</code> without full qualification? By using an import declaration such as: <br /><br><code>open Module1</code>
How does a <code>module</code> force clients to use fully qualified names? By using the <code>[<RequireQualifiedAccess>]</code> attribute at the <code>module</code> level.
What is a <code>do</code> binding used for? A <code>do</code> binding is used to execute code without defining a function or value.
What does the expression of a <code>do</code> binding return? <code>unit</code>
When is the code in a top-level (<code>module</code>) <code>do</code> binding executed? When the <code>module</code> is initialized.
What is the <code>do</code> binding syntax? <code>[ attributes ]<div>[ do ]expression</div></code>
What is the <code>fun</code> keyword for? The <code>fun</code> keyword defines a lambda expression, i.e. an anonymous function.
What is the <code>fun</code> keyword syntax? <code>fun parameter-list -> expression</code>
What determines the return value of a function? The last expression which generates a return value.
What is a <code>fun</code> keyword <code>parameter-list</code>? Names and optionally, types of parameters. Also the parameter-list can be composed of any F# patterns ex. <code>fun (a, b) -> ... </code> or <code>fun head :: tail -> ...</code>
What is the <code>rec</code> keyword used for? It is used in combination with <code>let</code> to define a recursive function.
What is the syntax of a recursive function bound with <code>let</code>? <code>let rec function-name parameter-list = <div> function-body</div></code>
How does one define mutually recursive functions? Define the first function with a <code>let rec</code> ... first and then immediately combine the second function to the first using <code>and</code>: <code><div>let rec Even x = </div><div> if x = 0 then true</div><div> else Odd (x - 1)</div><div>and Odd x =</div><div> if x = 1 then true</div><div> else Even (x - 1)</div></code>
Is structure a reference or value type? Structure is a value type, meaning it is stored directly on the stack, or, when used as fields or array elements, inline in the parent type.
What is the purpose of struct with respect to classes? Structure is a compact object type that can be more efficient than a class for types that have a small amount of data.
Syntax of struct declaration <code>[ attributes ]<div>type [accessibility-modifier] type-name =</div><div> struct</div><div> type-definition-elements</div><div> end</div><div>// or</div><div>[ attributes ]</div><div>[<StructAttribute>]</div><div>type [accessibility-modifier] type-name =</div><div> type-definition-elements</div></code>
What may appear in the <code>type-definition-elements</code> for a struct? Constructors, mutable and immutable fields and they can declare members and interface implementations.
What are structs not able to do? Participate in inheritance, use <code>let</code> or <code>do</code>-bindings and cannot recursively contain fields of their own type. They can contain reference cells that reference their own type however.
What replaces <code>let</code> bindings in <code>struct</code>s? Fields must be declared using the <code>val</code> keyword. <code>val</code> defines a keyword and type but does not allow initialization.
What does a struct initialize <code>val</code> declarations to? They are initialized to zero or null.
What does a struct implicit constructor do? Initializes <code>val</code> declarations to zero or null.
What might a struct explicit constructor do? It might accept values with which to initialize <code>val</code> declarations.
Does struct explicit initialization support zero-initialization? Yes, one may still zero-initialize a struct with an explicit initializer.
What do records represent? Simple aggregates of named values, optionally with members.
What is record syntax? <code>[ attributes ]<div>type [accessibility-modifier] typename = {</div><div> [mutable] label1 : type1;</div><div> [mutalbe] label2 : type2;</div><div> ...</div><div> }</div><div> member-list</div></code>
What is this?<br /><br><code>let mypoint = { x = 1.0; y = 2.0; }</code> This is a record expression. Enclosed in braces, type inferred by the compiler if labels don't match an existing record.
What is the record label precedence rule? The labels most recently declared take precedence over those of the previously declared type. This allows records with matching labels to handle ambiguous construction.
How does one explicitly specify labels for a record deferred by precedence? <code>let myPoint1 = { Point.x = 1.0; y = 2.0; }</code>
At record construction, are values required for all fields? Yes
At record construction time can values refer to other fields in the initialization expression? No
What is a 'copy and update record expression'? Copies an existing record, optionally changing some of the field values. <br /><br><code><div>let myRecord2 = { myRecord with Y = 100; }</div></code>
What is the default mutability of records? Immutable. But you can copy & update or specify a mutable field.
What is this? <code><div>type Car = {</div><div> Make : string</div><div> Model : string</div><div> }</div></code> Record
For records, why should one not use <code>[<DefaultAttribute>]</code> on fields? This encourages mutable fields. Better: define default instances of records with fields initialized to default values and then use copy and update record expression to set any fields that differ from default values.
How are record fields different from class fields? Record fields are automatically exposed as properties and are used in the creation and copying of records.
How is record construction different than class construction? Records cannot define a constructor. Instead construction is done using record expressions and record copy and update expressions. Classes have no direct relationship between constructor parameters, fields and properties.
What are the equality semantics for record? Like union and structure types, records have structural equality semantics (rather than reference equality semantics).
Can you use records for pattern matching? Yes
How are fields used in record pattern matching? Explicitly for structural comparison and/or with variables to be assigned when a match occurs.
What does F# inference offer? Generic function parameters to the degree the compiler can guarantee based on use.
Is F# static or dynamically typed? F# is statically typed i.e. the compiler deduces the exact type for each construct during compilation.
What determines the return type of a function? The return type of the last expression in the function.
What is the syntax for the entrypoint? <code>[<EntryPoint>]<div>let-function-binding</div></code>
What is the entry point? Where execution of a program formally starts.
What is required for an explicit entry point? Correct syntax, <code>[<EntryPoint>]</code> attribute, and it must be the last function in the last compiled file i.e. the last file in the project to compile.
What is the signature of the entry point function? <code>string array -> int</code>
Where is the implicit entry point? When there is no <code>[<EntryPoint>]</code> attribute that explicitly indicates the entry point, the top level bindings in the last file to be compiled are used as the entry point.
What is a tuple? A tuple is a grouping of unnamed but ordered values, possibly of different types.
What is tuple syntax? <code>( element, ... , element)</code>
How does one use matching to access items in a tuple? <code>let print tuple =<div> match tuple1 with</div><div> | (a, b) -> printfn "Pair %A %A" a b</div></code>
Name the two functions that access tuples ordinally. fst and snd. <code><div>let c = fst (1, 2)</div><div>let d = snd (1, 2)</div></code>
What does the use of tuples as function arguments avoid? Implicit currying of function arguments.
What is the type signature of the following?<br /><br><code>(10, 10.0, "ten")</code> <code>int * float * string</code>
What does <code>!</code> do with respect to reference cells? Dereferences the reference cell. <code><div>let refVar = ref 6</div><div>refVar := 50</div><div>printfn "%d" !refVar</div></code>
What are the three types of Active Patterns? Single, partial and multi-case.
What do single-case Active Patterns do? Convert the input into a new value.
What do partial-case Active Patterns do? Partial-case Active Patterns carve out an incomplete piece of the input space (such as only matching against strings that contain the letter 'x'.
What do multi-case Active Patterns do? Multi-case Active Patterns partition the input space into one of several values such as partitioning all possible integers into evens, odds or zero.
What operator are sigle-case Active Pattern function names bound within? Banana Clips: <code>(| activePatternName |)</code>
What does the following define?<br /><br><code>let (|FileExtension|) filePath = Path.GetExtension(filePath)</code> Single-case Active Pattern.
What operator are partial Active Patterns enclosed within? <code>(|ident|_|)</code>
What do partial Active Pattern functions return? The option type:<br /><br><code>Some('a)</code> or <code>None. </code>
What is the operator for block comments? <code>(* ... *)</code>
What is the operator for end of line comment? <code>//</code>
What characters can start an identifier? Any letter and <code>_</code>
All F# input files are assumed to be of which encoding? UTF-8
A type of the form <code>'ident</code> is called? A <i>variable type</i>. Ex. <code>'a</code>, <code>'T</code>, <code>'Key</code>
A type of the form <code>_</code> is called what? This is an <i>anonymous variable type. </i>
A type of the form <code>^ident</code> is called what? <code>^ident</code> is a <i>statically resolved type variable. </i>
Name this pattern: <br />_ Wildcard pattern.
Name this pattern: <br /><code>literal</code> Constant pattern.
Name this pattern: <br /><code>ident</code> Variable pattern.
Name this pattern: <br /><code>(pat, ..., pat)</code> Tuple pattern.
Name this pattern: <br /><code>[ pat; ...; pat; ]</code> List pattern.
Name this pattern: <br /><code>[| pat; ...; pat |]</code> Array pattern.
Name this pattern: <br /><code>{ id=pat; ...; id=pat }</code> Record pattern.
Name this pattern: <br /><code>id(pat, ..., pat)</code> Union case pattern.
Name this pattern: <br /><code>pat | pat</code> "Or" pattern.
Name this pattern: <br /><code>pat & pat</code> "Both" pattern.
Name this pattern:<br /><code>pat as id</code> Named pattern.
Name this pattern: <br /><code>:? type</code> Type test pattern.
Name this pattern: <br /><code>:? type as id</code> Type case pattern.
Name this pattern: <br /><code>null</code> Null pattern.
What kind of list is this: <br /><code>[ expr; ...; expr; ]</code> List literal.
What kind of list is this:<br /><code>[ expr..expr ]</code> Range list.
What kind of list is this:<br /><code>[ comp-expr ]</code> Generated list.
What list operation is this:<br /><code>expr :: expr</code> List cons.
What list operation is this:<br /><code>expr @ expr</code> List append.
Does F# use short-circuit boolean evaluation? Yes, F# uses short-circuit boolean evaluation.
What does the return keyword do? Nothing, there isn't one. Expressions return the value of the last subexpression to be evaluated.
What does the <code>if</code> keyword allow? The <code>if</code> keyword allows for the branching of control flow in a function.
What is the syntax of the <code>if</code> keyword? <code>if boolean-expresssion then expression1 [ else expression2 ]</code>
What are the implications of <code>if...then...else</code> being an expression? 1. It returns a value<div>2. Each branch must return the same type</div><div>3. If there is no explicit else branch it's type is <code>unit</code></div><div>4. Because of 3, if the <code>then</code> branch has any other type other than <code>unit</code> there must be an <code>else</code> branch with the same return type. </div>
What must the return type of an <code>if</code> with no corresponding <code>else</code> be? A single <code>if</code> with no corresponding <code>else</code> must return <code>unit</code>.
Describe this core type: <code>unit</code> Unit, the unit value, example: <code>()</code>
Describe these core types: <code>int</code>, <code>float</code>, etc. Concrete types, 42, 3.14 etc.
Describe this core type: <code>'a</code> Generic type, a generic (free) type
Describe this core type: <code>'a -> 'b</code> Function type, a function returning a value. Ex: <br /><br><code>fun x -> x + 1</code>
Describe this core type: <code>'a * 'b</code> Tuple type, an ordered grouping of pairs. ex. ("eggs", "ham")
Describe this core type: <code>'a list</code> List type, a list of values. ex: <code>[1; 2; 3], [1 .. 3]</code>
Describe this core type:<br /> <code>'a option</code> Option type, an optional value. ex. <code>Some(3)</code>, <code>None</code>.
What does <code>unit</code> represent? Nothing of consequence.
What does the <code>ignore</code> function do? The <code>ignore</code> function swallows the return type of a function if you want to return unit.
What is list range expression syntax? <code>[ start .. step .. stop ]</code>
What does the following list range expression produce in FSI?<br /><code>let x = [0 .. 10 .. 50]</code> <code>val x : int list = [0; 10; 20; 30; 40; 50; ]</code>
At the simplest level what is list comprehension syntax? At the simplest level list comprehension syntax is code in brackets. <code>[ expression ]</code>
How long will the code in the body of a list comprehension be executed? Until it terminates.
From the body of a list comprehension, what makes up elements returned by it? Elements are returned from the list comprehension using the <code>yield</code> keyword.
What resource is consumed during list comprehension generation? The list is fully generated in memory when created. If you find yourself creating lists with thousands of elements consider using a <code>seq<_>. </code>
How does <code>-></code> simplify list comprehensions with <code>for</code> loops? Rather than:<br><code> <div>let multiplesOf x = [ for i in 1 .. 10 do yield x * i ]</div><div></div></code>you can do:<code> <div>let multiplesOf x = [ for i in 1 .. 10 -> x * i ]</div></code>
What is the overall point of list comprehensions? List comprehensions enable you to quickly and concisely generate lists of data.
What are <i>aggregate operators</i> with respect to lists? A set of powerful functions that are useful for any collection of values.
Which List aggregate operator signature is this: <code>('a -> 'b) -> 'a list -> 'b list</code> This is <code>List.map</code>
What does the List aggregate operator <code>map</code> do? Map is a projection operation that creates a new list based on a provided function.
What does the List aggregate operation <code>fold</code> do? <code>fold</code> distills a list of values into a single value.
What are the two List aggregate operators for <code>fold</code>? <code>List.reduce</code> and <code>List.fold. </code><div>Reduce:</div> <code>('a -> 'a -> 'a) -> 'a list -> 'a<div></div></code>Fold:<br /> <code>('acc -> 'b -> 'acc) -> 'acc -> 'b list -> 'acc</code>
In what direction do <code>List.reduce</code> and <code>List.fold</code> operate? <code>List.reduce</code> and <code>List.fold</code> operate from left to right.
What are the right to left equivalents of <code>List.reduce</code> and <code>List.fold</code>? The right to left equivalents of List.reduce and List.fold are List.reduceBack and List.foldBack.
What does <code>List.iter</code> do? <code>List.iter</code> calls a function with return type of <code>unit</code> on each item in the list.
What is the signature of <code>List.iter</code>? <code>('a -> unit) -> 'a list -> unit</code>
Because <code>List.iter</code> returns <code>unit</code>, what is it primarily used for? <code>List.iter</code> is primarily used for evaluating the side-effect of the given function.
What is the best way to represent a value that may or may not exist? The <code>option</code> type is the best way to represent something that may or may not exist.
What are the two possible values of the <code>option</code> type? <code>Some('a)</code> and <code>None</code>
What common idiom from other languages does the <code>option</code> type replace? A common idiom the <code>option</code> type replaces is null - which means the absence of a value.
What is the <i>anonymous</i> <code>module</code>? The <i>anonymous</i> <code>module</code> is where, by default, F# puts all your code - and it matches the name of the code file with the first letter capitalized.
How does one explicitly create a <code>module</code>? One explicitly creates a <code>module</code> by using the <code>module</code> keyword at the top of a source file.
Does F# support nested modules? Yes, F# supports nested modules.
How does one declare a nested <code>module</code>? To declare a nested module, use the <code>module</code> keyword followed by the name of the module and an equals sign. Nested modules must be indented to disambiguate them from the top-level module.
What must be done to disambiguate a nested <code>module</code> from the top-level <code>module</code>? Nested modules must be indented to be disambiguated from the top-level <code>module</code>.
What is the alternative to modules? Namespaces are the alternative to modules.
Namespaces can do just what modules can with which single exception? Namespaces cannot contain values, they can only contain types.
Can namespaces be nested? Namespaces can be nested. They are nested not using whitespace like modules, but rather with dotting. So, <code>PlayingCards.Poker</code> would be a namespace nested within <code>PlayingCards</code>.
What is the software-engineering difference in usage between <code>module</code> and <code>namespace</code>? The difference is that <code>module</code> is used for rapid prototyping while <code>namespace</code> is used for larger-scale projects using an object oriented approach.
Name the term for when a function somehow changes the state of a program. Changing the state of a program, or file system is known as a <i>side-effect. </i>
By default, how changeable the names of things in a functional language? Not changeable, they are immutable.
What is the general benefit of immutability? Immutability limits unintended side-effects - immutable values help you write safer code because you can't screw up what you can't change.
To what value must all standalone expressions evaluate to? Standalone expressions must always evaluate to the <code>unit</code> value.
What's a common error interfacing with .NET libraries due to currying? .NET libraries like <code>System.IO.StringReader</code> have methods like <code>ReadLine</code> which require <code>unit</code> arguments, so they must be called as <code>ReadLine()</code>. Calling as <code>ReadLine</code> compiles, but is an error at runtime.
What is the signature of this operator? <code>|></code> <code>let (|>) x f = f x</code><div>All this does is allow you to put the function argument in front of the function rather than after. That's all. </div>
What is the signature of this operator? <code><|</code> This is the reverse pipe operator and its signature is: <code>let (<|) f x = f x</code><br><div>It reduces the need for parentheses and can make the code cleaner.</div><br><code><br><div>printf "%i" 1+2 // error</div><br><div>printf "%i" (1+2) // using parens</div><br><div>printf "%i" <| 1 + 2 // using reverse pipe</div><br></code>
What is the idea of partial function application? The idea of partial application is that if you fix the first N parameters of a function you get a partial function of the remaining parameters.
What makes a significant difference for the ease of use of partial application? The order of parameters makes a big difference in the ease of use of partial application.
What are the guidelines to design for better partial application? 1. Put earlier: parameters more likely to be static. <div>2. Put last: the datastructure or collection (or most varying argument)</div><div>3. For well-known operations (ex. subtract) put in the expected order. </div>
What change makes .NET base-class library functions more idiomatic in F#? Wrapping .NET base-class library functions for partial application makes them more idiomatic in F#. <br><code><div>let replace oldStr newStr (s:string) = </div><div> s.Replace(oldValue=oldStr, newValue=newStr)</div></code>
What might we call a monoid in a programming context today? We might call a monoid <code>ICombinable</code>.
In programming terms is there a connection between monad and monoid? No, there is no programming connection but there is a mathematical connection.
What are the three requirements for something to be a monoid? <div>You start with a bunch of things <i>and</i> some way of combining them two at a time.</div>1. Closure: The result of combining things is always another one of the things. <div>2. Associativity: When combining more than two things, which pairwise combination you do first doesn't matter. </div><div>3. Identity Element: There is a special thing called "zero" such that when you combine any thing with "zero" you get the original thing back. </div>
What is the Closure rule for monoids? The closure rule states that the result of combining two things is always another one of the things. <code>('a -> 'a -> 'a)</code>
What is the Associativity rule for monoids? The associativity rule for monoids states that when combining more than two things, which pairwise combination you do first doesn't matter.
What is the Identity Element rule for monoids? The Identity Element rule for monoids states that there is a special thing called "zero" such that when you combine any thing with "zero" you get the original thing back.
What is the key for identifying the zero for a monoid? The zero value depends very much on the <i>operation</i> not just the set of things.
What are the key two parts to the definition of a particular monoid? The two parts of the definition of any particular monoid are the <i>things</i> and the <i>operation</i>. Ex. "the integers" is not a monoid, but "the integers under addition" is a monoid.
What is the term for a system that follows the first two rules for a monoid but not the zero rule? A system that only follows the first two rules but has no zero is referred to as a semigroup.
What is the practical benefit of the closure rule for monoids? The practical benefit of the closure rule for monoids is that you can convert pairwise operations that work on lists or sequences. <code><div>1 + 2 + 3 </div></code><div>becomes</div><code><div>[1;2;3] |> List.reduce (+)</div></code>
What is the practical benefit of the monoid rule of Associativity? When pairwise operations can be conducted in any order it opens up the option to do: <div>- Divide and Conquer Algorithms</div><div>- Parallelization</div><div>- Incrementalism</div>
In terms of design patterns, what is a monoid? A monoid is a way to describe an aggregation pattern. We have a list of things, we have some way of combining them and we get a single aggregated object back at the end. Or, in F# terms: <div>Monoid Aggregation: <code>'a list -> 'a</code></div>
What are some conversational clues you are dealing with a monoid? When you are designing code and start using terms like "sum", "product", "composition" or "concatenation."
When are <code>lazy</code> computations evaluated? <code>lazy</code> computations are evaluated when the result is needed.
What is the syntax for a <code>lazy</code> computation? <code>let identifier = lazy ( expression )</code>
How does one cause a <code>lazy</code> computation to be performed? To force the computation to be performed you call the method <code>Force</code>. <code><div>let x = 10</div><div>let result = lazy (x + 10)</div><div>printfn "%d" (result.Force())</div></code>
What do subsequent calls to <code>lazy Force</code> return? Subsequent calls to <code>Force</code> return the same result and do not execute any code.
What is a sequence? A sequence is a logical series of elements, all of one type.
When are sequences useful? Sequences are useful when you have a large ordered collection of data but do not necessarily expect to use all of the elements.
When are individual elements of a sequence computed? Individual elements of a sequence are computed only as required, so a sequence can provide better performance than a list in situations in which not all the elements are used.
What is a primary difference between lists and sequences? Lists have all of their members in memory, while sequences compute each individual elements only as required.
What is the F# type for sequences? The F# type for sequences is <code>seq<'T></code> which is an alias for <code>IEnumerable<T></code>. Therefore any .NET Framework type that implements <code>IEnumerable</code> can be used as a sequence.
What is the .NET type backing <code>seq<'T></code>? The .NET backing type is <code>IEnumerable<T></code>
What is a sequence expression? A sequence expression is an expression that evaluates to a sequence. The simplest form specifies a range ex. <br /><code>seq { 1 .. 5 }</code>
When does one use <code>yield</code> in a sequence expression? One uses <code>yield</code> when each iteration is expected to generate a single element of the sequence.
When does one use <code>yield!</code> in a sequence expression? One uses <code>yield!</code> in a sequence expression when each iteration is expected to produce a sequence of elements. Elements generated from each iteration are concatenated to produce the final sequence.
What is happening in the following code:<br><code><pre>let rec inorder tree =<br> seq {<br> match tree with<br> | Tree(x, left, right) -><br> yield! inorder left<br> yield x<br> yield! inorder right<br> | Leaf x -> yield x<br> }<br></pre></code><br> This code is a sequence expression that uses both <code>yield</code> to produce single elements and <code>yield!</code> to produce lists of elements. It does this by matching on a discriminated union.
What feature allows for the creation of ad-hoc types? Type abbreviations allow you to create ad-hoc types. ex. <br /><br><code>type NodeList = List<node></code>
What is a fundamental limitation of type systems that TypeProviders address? TypeProviders address the fundamental limitation of type systems in that type systems only describe the shape of data <i>within</i> programs.
What feature uses the F# compiler to wrap external data so you can focus coding? TypeProviders are the F# feature that leverages the F# compiler to handle all the type-wrapper-conversion-generation stuff for you so you can just focus on coding.
At what point during code lifetime does a TypeProvider generate wrappers? Wrappers provided by TypeProviders are generated at <i>design time</i> so you can interact with them in the IDE or FSI window.
Where is type information generated by TypeProviders stored at runtime? At compile time the type information from the TypeProvider will be baked into your program - not into a separate library.
How do TypeProviders enable scaling beyond any particular IDE? Traditionally IDEs implemented TypeProvider-like functionality, but because developers can implement their own they are not limited by or to any particular IDE.
With respect to SQL, what does an SQL TypeProvider replace in a project? An SQL TypeProvider takes the place of an ORM (Object relational mapping).
What type of connection does a <code>SqlDataConnection</code> expect? A <code>SqlDataConnection</code> expects a <i>live</i> connection - but you can generate type information with a <code>DbmlFile</code> Provider as a stand-in.
A DbmlFile provider generates the same type information as which built in provider? <div align="left">A DbmlFile provider generates the same type information as the SqlDataConnection type provider.</div>
Rather than a live connection to a Sql database, on what does a DbmlFile provider operate? A Dbml provider operates on a schema file describing a database's structure.
Before writing a new TypeProvider, what is the first question to ask about the information source? Does the information source have a schema and what is the entropy of that schema? Will it change? Will it change during coding/between coding sessions/program execution? TypeProviders are best for stable schemas.
Describe the Option.get<'a> function. Gets the value associated with the option. <div>Signature: </div><div>get : 'a option -> 'a</div><div>Usage: </div><div>get option</div><div>Throws ArgumentException when option is None. </div>
What is the signature of Option.get<'a>? get : 'a option -> 'a
What is the usage of Option.get<'a>? get option
What does calling Option.get<'a> on None do? Calling get option on None throws ArgumentException.
What is Option.iter used for? Option.iter is used to call a unit function on an option whose value is not None.
What is the signature of Option.iter? ('a -> unit) -> 'a option -> unit
In FSI how does one display help information? By using the #help directive.
In FSI how does one specify an assembly search path? One specifies an assembly search path using the #l directive with quotation marks.
In FSI how does one read a source file, compile and run it? One reads, compiles and runs a source file using the #load directive.
In FSI how does one leave the program? One leaves FSI by using the #quit directive.
In FSI how does one reference an assembly? One references an assembly in FSI using the #r directive.
In FSI how does one display performance information? One uses the #time ["on"|"off"] directive for information on real time, CPU time and garbage collection information on each section of the code that is interpreted and executed.
How are modules implemented by the compiler? Modules are implemented as a common language runtime (CLR) class that has only static members.
What is the default <i>accessibility-modifier</i> for modules? The default <i>accessibility-modifier</i> for modules is public.
List the <i>accessibility-modifiers available </i>for modules. The <i>accessibility-modifier</i> can be one of public, private or internal.
What does the [<AutoOpen>] attribute do with respect to Modules? Modules with the [<AutoOpen>] attribute do not need to be opened but instead are opened automatically.
What do type extensions allow? Type extensions allow you to add new members to previously defined object types.
What is the syntax for type extension? type typename with<div> member self-identifier.member-name =</div><div> body</div><div> ...</div><div> [ end ]</div>
What are the two forms of type extension? 1) Intrinsic extension is an extension that appears in the same namespace or module, in the same source file and assembly as the type being extended. <div>2) Optional extension appears outside the original module, namespace or assembly of the type being extended. </div>
Of the two forms of type extension, which appears on the type when it is examined by reflection? Intrinsic extensions appear on the type when the type is examined by reflection, optional extensions do not.
Of the two forms of type extension, which does not appear on the type when it is examined by reflection? Optional extensions do not appear on the type when the type is examined by reflection, while intrinsic extensions do appear on the type under reflection.
When are optional extensions in scope? Optional extensions are only in scope when the <code>module</code> containing that extension is open.
What is the syntax for creating a type extension for a type abbreviation. There isn't one, you can't create a type extension for a type abbreviation.
What types of members are allowed for type extensions? Members may be static or instance i.e. static or instance properties or static or instance methods.
How are optional extension members compiled? Optional extension members are compiled to static members for which the object instance is passed implicitly as the first parameter.
How do instance members defined as type extensions behave at runtime? As instance members, although they are compiled to static members behave as instance members at runtime.
What type of extension methods are not allowed as type extensions? Extension methods may not be <code>virtual</code> or <code>abstract</code>.
Can extension methods overload? Extension methods may overload methods of the same name.
To which method does the compiler give preference in the case of an ambiguous call between a type method and extension method? The compiler gives preference to non-extension methods in the case of an ambiguous call.
How might ambiguity occur in client code when dealing with extension members for a particular type? Ambiguity occurs if a client opens two different scopes that define the same member names.
Where can you overload arithmetic operators? You can overload arithmetic operators at the <code>class</code>, record type or global level.
What is the syntax for overloading an arithmetic operator as a class or record member? static member (operator-symbols) (parameter-list) =<div> method-body</div>
What is the syntax for overloading arithmetic operators at the global level? let [inline] (operator-symbols) parameter-list =<div> function-body</div>
Operator overloads for classes and records must be of what type of method? Operator overloads for classes and records must be methods of static type.
What symbol indicates an operator in an operator overload declaration is unary rather than binary? The tilde (<code>~</code>) symbol indicates that an operator is unary rather than binary. <div><code>static member (~-) (v : Vector)</code></div>
What is the inline modifier used for? The inline modifier can be applied to functions to be integrated directly into the calling code.
When must you use the <code>inline</code> modifier for a function? When a function is parameterized by static type parameters you must <code>inline</code> the function. There is no such restriction for ordinary generic type parameters.
What must you do before using the <code>inline</code> function modifier? You should try all other optimization techniques and measure performance before using the <code>inline</code> function modifier.
What are the risks of using the inline function modifier? Overuse of the inline function modifier can cause your code to be less resistant to changes in compiler optimizations and the implementation of library functions. They do not always result in improved performance.
What type of function cannot have statically resolved type parameters? Non-<code>inline</code> functions may not have statically resolved type parameters.
At runtime, what does the presence of the inline function modifier affect? The presence of inline affects type inference. Inline functions can have statically-resolved type parameters.
What is the signature of this function: <div>let inline printAsFloatingPoint number = </div><div> printfn "%f" (float number)</div> ^a -> unit when ^a : (static member op_Explicit : ^a -> float)
What is class constructor syntax? new (argument-list) = constructor body
Describe class definition syntax. type [access-modifier] type-name [type-params] [access-modifier] ( parameter-list ) [as identifier] =<div> [ class ]</div><div> [ inherit base-type-name(base-constructor-args) ]</div><div> [ let-bindings ]</div><div> [ do-bindings ]</div><div> member-list</div><div> [ end ]</div>
What is the primary type concept that supports object oriented programming in F#? The class is the primary type concept that supports object oriented programming in F#.
What does <i>type-params</i> describe in a class definition? <i>Type-params</i> describes optional generic type parameters. It consists of type parameter names and constraints enclosed by angle (< and >).
What is the default visibility of a class? The default visibility of a class is public.
What does the first <i>access-modifier </i>apply to in a class definition? The first <i>access-modifier </i>applies to the type.
What does the second <i>access-modifier</i> apply to in the definition of a class? The second <i>access-modifier</i> applies to the primary constructor.
What keyword specifies the base for a class? The inherit keyword specifies the base for a class.
When a class inherits from a base, what three things must one do for the base constructor? Call the base constructor with arguments, wrapped in parentheses.
In a class definition what does the <i>member-list </i>consist of? The <i>member-list</i> consists of additional constructors, instance and static method declarations, interface declarations, abstract bindings and property and event declarations.
What is the optional as keyword in a class definition used for? The as keyword is used with an identifier to give the name to the instance variable, or self-identifier which can be used in the type definition to refer to the instance of the type.
What do the keywords class and end do? They optionally mark the start and end of a class definition.
What keyword allows the definition of mutually recursive types? The and keyword allows for the definition of mutually recursive types.
What is the difference in how F# class constructors work and other .NET languages? F# classes always have a primary constructor whose arguments are described in the <i>parameter-list</i> that follows the type name and whose body consists of let/let rec bindings at the start of the class declaration and the do bindings that follow.
Where are the arguments of the class primary constructor in scope? The arguments of the primary constructor are in scope throughout the class declaration.
What does the body of a class primary constructor consist of? The body of a class primary constructor consists of let/let rec bindings and do bindings that follow.
How do you add additional constructors to a class? You can add additional constructors to a class using the new keyword.
What must the body of a new class constructor invoke? The body of a new constructor must invoke the primary constructor.
What is the following code doing?<div>type MyClass1(x: int, y: int) =</div><div> new() = MyClass1(0, 0)</div> This is an additional constructor invoking the primary constructor.
When do <code>let</code> and <code>do</code> bindings run when within a <code>class</code> definition? <code>let</code> and <code>do</code> bindings in a <code>class</code> definition run whenever a <code>class</code><code> instance is created. </code>
In a class definition, what is a let binding that is a function compiled into? A let binding that is a function is compiled into a member.
In a class definition, what is a let binding that is a value compiled into? If a let binding is a value that is not used in any function or member it is compiled into a variable local to the constructor.
What is a type abbreviation? A type abbreviation is an alias or alternate name for a type. ex. type sizeType = uint32
What is the syntax for type abbreviation? type type-abbreviation = type-name
What are the uses of type abbreviations? You can use type abbreviations to give a type a more meaningful name for readability, or an easy to use name for a type that's otherwise difficult to write out.
How are type abbreviations compiled? They aren't preserved in the .NET Framework MSIL - so if you call an F# assembly from another .NET Framework language you'll have to use the underlying type.
What is the following: <div><code>type transform<'a> = 'a -> 'a</code></div> Transform is a type abbreviation that represents a function that takes a single argument of any type and returns a single value of that same type.
With respect to syntax, what do square brackets around a production symbolize? Square brackets symbolize an optional production.
With respect to syntax, what do literal productions symbolize? A literal production symbolizes a required production within the larger construct.
Define Symbol or Operator: ! 1. Dereferences a reference cell<div>2. After keyword, invokes modified control within a workflow</div>
Define Symbol or Operator: != Doesn't exist - use <> for inequality operations
Define Symbol or Operator: '' Delimits a text string
Define Symbol or Operator: """ Delimits a verbatim string. Differs from @ because it allows you to included double quotes without escaping.
Define Symbol or Operator: # 1. Compiler directive ex. #light, #if symbol #else<div>2. When used on a type, indicates a flexible type, which refers to a type or any one of its derived types</div>
Define Symbol or Operator: $ Used internally for compiler-generated symbol names
Define Symbol or Operator: % 1. Modulus<div>2. Code quotation splicing operations</div>
Define Symbol or Operator: %? Computes modulus when right side is nullable type.
Define Symbol or Operator: & 1. Computes address of mutable value - for use in language interop<div>2. Used in AND patterns</div>
Define Symbol or Operator: && Boolean AND
Define Symbol or Operator: &&& Bitwise AND
Define Symbol or Operator: ' 1. Delimits single character literal<div>2. Indicates generic type parameter</div>
Define Symbol or Operator: ``..`` Delimits an identifier that would otherwise not be a legal identifier, such as a language keyword.
Define Symbol or Operator: () Represents the single value of the unit type.
Define Symbol or Operator: (...) 1. Indicates the order in which expressions are evaluated<div>2. Delimits a tuple</div><div>3. Used in operator definitions</div>
Define Symbol or Operator: (*...*) Multiline comments
Define Symbol or Operator: (|...|) Single case active pattern - aka banana clips
Define Symbol or Operator: * 1. As binary operator: multiplies left and right<div>2. In types, indicates pairing in a tuple</div><div>3. Used in units of measure types</div>
Define Symbol or Operator: *? Multiplies the left and right sides when the right side is a nullable type.
Define Symbol or Operator: ** Exponentiation (x ** y)
Define Symbol or Operator: + 1. Binary: Adds left and right sides<div>2. Unary: indicates positive quantity</div>
Define Symbol or Operator: +? Adds right and left sides where right side is nullable type
Define Symbol or Operator: , 1. Separates elements of a tuple<div>2. Separates elements of type parameters</div>
Define Symbol or Operator: -> 1. In functions, delimits arguments and return values<div>2. Yields an expression in sequence expressions (replaces do yield)</div><div>3. Used in match expressions</div>
Define Symbol or Operator: . 1. Member access. Separates individual names from fully qualified name. <div>2. Specifies a decimal point for floats</div>
Define Symbol or Operator: .. Range operator.
Define Symbol or Operator:<br> .. .. Range operator with increment. ex. start..step..stop
Define Symbol or Operator: <br>.[...] Accesses an array element
Define Symbol or Operator: / 1. Division, divides numerator from denominator<div>2. Used in units of measure types</div>
Define Symbol or Operator: /? Division when right side is nullable type
Define Symbol or Operator: // Single line comment
Define Symbol or Operator: /// XML Comment - fully supported, just not autocompleted by entry of the triple-slash by IDE
Define Symbol or Operator: : In a type annotation, separates a parameter or member name from its type
Define Symbol or Operator: :: 1. Creates a list. Element on left is added to list on right. <div>2. Used in pattern matching to separate parts of a list. </div>
Define Symbol or Operator: := Assigns a value to a reference cell
Define Symbol or Operator: :> Converts a type to a type that is higher in the hierarchy
Define Symbol or Operator: :? Type Test Operator: Returns true if the value matches the specified type, otherwise returns false
Define Symbol or Operator: :?> Converts a type to a type that is lower in the hierarchy
Define Symbol or Operator: ; 1. Separates expressions (in verbose syntax)<div>2. Separates elements of a list</div><div>3. Separates fields of a record</div>
Define Symbol or Operator: < Less than
Define Symbol or Operator: <? Less than when right side is nullable type
Define Symbol or Operator: << Backward Composition Operator: Composes functions in reverse order.
Define Symbol or Operator: <<< Shifts bits in the quantity on the left side to the left by the number of bits specified on the right side.
Define Symbol or Operator: <- Mutation: Assigns value to a variable
Define Symbol or Operator: <...> Delimits type parameters
Define Symbol or Operator: <> Not equals
Define Symbol or Operator: <>? Not equals when right side is nullable type.
Define Symbol or Operator: <= Less than or equal
Define Symbol or Operator: <=? Less than or equal with nullable type on right side
Define Symbol or Operator: <| Backward pipe: passes the result of the expression on the right to the function on the left side.
Define Symbol or Operator: <|| Passes the tuple of two arguments on the right side to the function on the left side.
Define Symbol or Operator: <||| Passes the tuple of three arguments on the right side to the function on the left side.
Define Symbol or Operator: <@...@> Delimits a typed code quotation
Define Symbol or Operator: <@@...@@> Delimits an untyped code quotation
Define Symbol or Operator: = Equality operator
Define Symbol or Operator: =? Equality operator when right side is nullable type.
Define Symbol or Operator: == Not in the language - use = for equality operations
Define Symbol or Operator: > Greater than
Define Symbol or Operator: >? Greater than when right side is nullable type.
Define Symbol or Operator: >> Forward Composition Operator: Composes two functions
Define Symbol or Operator: >>> Shifts bits in the quantity on the left side to the right by the number of places specified on the right side
Define Symbol or Operator: >= Greater than or equal
Define Symbol or Operator: ? 1. Specifies an optional argument<div>2. Used as an operator for dynamic method and property calls. Provide your own implementation. </div>
Define Symbol or Operator: @ 1. Concatenates two lists<div>2. When placed before a string literal it indicates that the string will be interpreted verbatim - ie. no interpretation of escape characters. </div>
Define Symbol or Operator: [...] Delimits elements of a list
Define Symbol or Operator: [|...|] Delimits elements of an array
Define Symbol or Operator: [<...>] Delimits an attribute
Define Symbol or Operator: \ Escapes next character in string literal
Define Symbol or Operator: ^ 1. Specifies static type parameter resolved at compile rather than runtime<div>2. Concatenates strings</div>
Define Symbol or Operator: ^^^ Computes bitwise exclusive OR operation
Define Symbol or Operator: _ 1. Wildcard pattern<div>2. Specifies an anonymous generic parameter</div>
Define Symbol or Operator: ` Used internally to indicate a generic type parameter
Define Symbol or Operator: {...} 1. Delimits a squence of expressions and computation expressions<div>2. Used in record definitions</div>
Define Symbol or Operator: <br /><code>|</code> Delimits individual match cases<div>Delimits individual discriminated union cases</div><div>Delimits enumeration values. </div>
Define Symbol or Operator: || Boolean OR
Define Symbol or Operator: ||| Bitwise OR
Define Symbol or Operator: |> Forward Pipe Operator: Passes the result of the left side to the function on the right side.
Define Symbol or Operator: ||> Passes the tuple of two arguments on the left side to the function on the right side.
Define Symbol or Operator: |||> Passes the tuple of three arguments on the left side to the function on the right side.
Define Symbol or Operator: ~~ Used to declare an overload for the unary negation operator
Define Symbol or Operator: ~~~ Computes bitwise NOT
Define Symbol or Operator: ~- Used to declare an overload for the unary minus operator.
Define Symbol or Operator: ~+ Used to declare an overload to the unary plus operator.
What is the type provider mechanism primarily designed for injecting? Stable <i>data</i> and <i>services</i> information spaces into the F# programming experience.
What are <i>code quotations</i> as a language feature? <i>Code quotations</i> are a language feature that enables you to generate and work with F# code expressions programmatically.
What do code quotations specifically generate that are then manipulated? Code quotations generate abstract syntax trees which can then be traversed and processed.
What is an example of why a code expression generated abstract syntax tree would be traversed? You could traverse the tree to generate F# code or generate code in some other language.
What is a <i>quoted expression</i>? A <i>quoted expression</i> is an F# expression in your code that is delimited in such a way that it is not compiled as part of your program but instead compiled into an object that represents an F# expression.
What are the two ways you can mark a <i>quoted expression?</i> You can either mark a <i>quoted expression </i>with or without type information. <br>With: <@...@> <br>Without: <@@...@@>
What type of quoted expression is this: <div><code>let expr : Expr<int> = <@ 1 + 1 @></code></div> This is a typed quoted expression.
What type of quoted expression is this: <div><code>let expr : Expr = <@@ 1 + 1 @@></code></div> This is an untyped quoted expression.
To use code quotations which namespace must be opened? open Microsoft.FSharp.Quotations
What makes traversing a large expression tree built by code expressions faster? Traversing a large expression tree is faster if you do not include type information.
What is the resulting type of an expression quoted with the typed symbols? The resulting type is Expr<'a> where 'a is determined by F# type inference.
What is the resulting type of a quoted expression without type information? The resulting type of an untyped quoted expression is the non-generic type Expr.
How do you get the untyped Expr from a typed Expr? By calling the Raw property on Expr<'a>
A valid code quotation creates an expression with what property? A valid code quotation creates an expression that is <i>complete</i>. <div>Incomplete: <br><@ let f x = x + 1 @></div><div>Complete: <br><@ let f x = x + 1 in f 10 @></div>
How valid is this code quotation?<div><@ let name x = x + "foo" @></div> Invalid, the code quotation does not create a complete expression.
How valid is this code quotation?<div><@ let name x = x + "bar" in name "ba" @></div> Valid, the code quotation creates a complete expression.
What provides a variety of methods to generate F# expression objects programmatically without using quoted expressions? The <code>Expr</code> class has many static methods for generating quoted expressions programmatically.
What's a powerful technique to read through the abstract syntax tree generated by a code quotation? Active Patterns are a powerful technique and many are provided in <code>Microsoft.FSharp.Quotations</code><br /><code>.Patterns | DerivedPatterns</code>
What is the syntax for a complete active pattern definition? let (|identifier1|identifier2|...|identifier7|) [ arguments ] = expression
What is the syntax for a partial active pattern definition? let (|identifier|_|) [ arguments ] = expression
What do the identifiers of a complete active pattern represent? The identifiers to a complete active pattern represent names for subsets of the set of all values of the arguments.
What does the expression of a complete active pattern do? The expression for a complete active pattern describes the form into which to decompose the data.
What is the name of a function created by a let binding with banana clips? A function created by a let binding with banana clips is known as an <i>active recognizer</i>.
What is the definition of (|RGB|) here?<div>let printRGB (col: System.Drawing.Color) = </div><div>match col with</div><div>| RGB(r,g,b) -> printfn " r: %d g: %d b: %d" r g b</div> let (|RGB|) (col : System.Drawing.Color) = <div> (col.R, col.G, col.B)</div>
How many arguments do active patterns always take? They always take at least one argument - for the item being matched.
What is a much more abstract way to traverse an F# expression tree than Quotations.Patterns or DerivedPatterns? Microsoft.FSharp.<br>Quotations.ExprShape allows you to match across shapes such as ShapeVar, ShapeLambda or ShapeCombination.
What are the splicing operators % and %% about? The splicing operators allow one to splice typed and untyped information straight into a code expression - particularly useful for splicing in values returned from an active pattern match expression.
What is an erased type? A type that when used is "erased" to type obj and all uses of the type will appear as type obj in compiled code.
What is used to subvert type erasure? With all uses of type erasure, you can use explicit boxing and unboxing and casting to subvert the erased types.
What could result from subverting an erased type by casting? A cast exception may result when attempting to cast to an invalid type from an erased type.
An erased type has which .NET type? None - not even object. An erased type has no real .NET type. This means you can't do accurate reflection over the type.
Can you define erased types in F#? No, you can't define erased types in F# itself - only provided types may be erased.
What is the exact opposite operation of type erasure? Type inference is the exact opposite operation of type erasure.
An implicitly typed term is well-typed iff what? An implicitly typed term is well-typed iff it is the erasure of a well-typed explicitly typed lambda term.
What is the compile-time process of type erasure? Type erasure is the compile-time process by which explicit type annotations are removed from a program.
At runtime what is one thing not possible on an erased type? Accurate reflection is not possible on an erased type since it has no real .NET type.
When is no representation for an erased provided type required? When the erased provided type contains only static properties and members - and no constructors or anything instance related.
What are the representations of a provided type? The set of possible objects for an erased provided type are called its representations.
What is the erasure of a provided type with respect to compiled .NET code? The erasure of a provided type is how the type appears in compiled .NET code.
What is the erasure of a provided type with respect to the object hierarchy? The erasure of a provided class type is always the first non-erased base type in the inheritance chain of the type.
What is the erasure of a provided type when the provided type is an interface? The erasure of a provided erased interface type is always Object.
All representations of a provided type must be compatible with what? All representations of a provided type must be compatible with the erasure of the provided type.
When you establish a provided type with <code>ProvidedTypeDefinition</code> what does <code>baseType</code> parameter specify? The <code>baseType</code> parameter specifies what the provided type erasure will be - aka what the provided type will look like in compiled code.
What is this code specifying with respect to representation of provided objects?<div><br /><code>ProvidedConstructor(parameters = [], </div><div> InvokeCode= (fun args -> <@@ (new List<string>()) :> obj @@>))</code></div> This code is specifying a representation of provided objects in terms of a list of strings.
What is the following specifying with respect to provided type representations?<div><br /></div><code>type InternalData() = </div><div> let data = List<string>()</div><div> member x.RuntimeCall() = data.Count</div><div><br /></div><div>ProvidedConstructor(parameters = [],</div><div> InvokeCode = (fun args -> <@@ (new InternalData()) :> obj @@>)) </div></code> InternalData is defined in the type provider and is used at runtime to form the representation along with one or more runtime operations. Provided members can then construct instances of this object type.
Can you use a type provider defined type as the type erasure for a provided type? Yes, you can use a type you have defined as the baseType when constructing the <br><code><pre>ProvidedTypeDefinition(..., baseType = Some typeof<InternalData> )<br>...<br> ProvidedConstructor(..., <br> InvokeCode = (fun args -> <@@ new InternalData() @@>, ...)</pre></code>
Define keyword: abstract Indicates a method that has either no implementation in the type in which it is declared or that it is virtual and has a default implementation.
Define keyword: and Used to create mutally recursive bindings, in property declarations and with multiple constraints on generic parameters.
Define keyword: as 1. Optionally used to give a name to the self-identifier in a class<div>2. Used to give a name to a whole pattern within a pattern match. ex.<br /><br><code>(a, b) as tuple1</code></div>
Define keyword: assert Used to verify code during debugging
Define keyword: base Used by derived classes to refer to the parent class.
Define keyword: begin In verbose syntax indicates start of a code block.
Define keyword: class In verbose syntax indicates start of a class.
Define keyword: default 1. Indicates an implementation of an abstract method<div>2. Used together with an abstract method declaration to create a virtual method. </div>
Define keyword: delegate Used to declare a delegate
Define keyword: do 1. Looping constructs<div>2. Execute expression returning unit</div>
Define keyword: done In verbose, indicates end of a block of code in a looping expression.
Define keyword: downcast Convert type to one that is lower in the inheritance chain
Define keyword: downto In a for expression, used when counting backward
Define keyword: elif Used in conditional branching, a short form of else if
Define keyword: else Used in conditional branching
Define keyword: end 1. Types and type extensions: indicates end of a section of member definitions<div>2. Verbose: used to specify the end of a clode block that starts with the begin keyword</div>
Define keyword: exception Used to declare an exception type. ex. exception MyError of string
What is the syntax of creating a new exception type? exception exception-type of argument-type
Define keyword: extern Indicates that a declared program element is defined in another binary or assembly.
Define keyword: false Boolean literal
Define keyword: finally Used with try to introduce a block of code that will execute regardless of when an exception occurs.
Define keyword: for Looping construct. ex. for...to and for...in
Define keyword: fun Creates a lambda function
Define keyword: global Used to put names into the .NET top-level namespace. ex. <div>namespace global</div><div><br /></div><div>type someType() = ...</div>
Define keyword: if Conditional branching
Define keyword: in 1. Sequence expressions ex. for...in<div>2. Verbose: separates expressions from bindings. ex. let f x = x + 1 in f 3</div>
Define keyword: inherit Specifies a base class or base interface in a class.
Define keyword: inline Indicates a function that should be integrated directly into calling code.
Define keyword: interface Declares and implements an interface
Define keyword: internal Visibility modifier - visible inside an assembly and not outside.
Define keyword: lazy Specifies a computation performed only on demand.
Define keyword: let Associates (binds) a name to a value or function.
Define keyword: let! 1. Asynchronous workflows: binds a name to the result of another asynchronous workflow. <div>2. Or, in other workflows, binds the name to the result of workflows of the same type. </div>
Define keyword: match Branching operator based on comparing a value to a pattern.
Define keyword: member Declares a property or method on an object type.
Define keyword: module Used to associate a name with a group of related types, values and functions - logically separating them from other code.
Define keyword: mutable Used to declare a variable :-|
Define keyword: namespace Used to associate a name with a group of related types and modules - logically separating them from other code.
Define keyword: new 1. Used to declare, define or invoke an object constructor. <div>2. With generic parameter constraints, used to require that a type must have a certain constructor. </div>
Define keyword: not 1. Not a keyword alone. <div>2. Used as 'not struct' to require type constraint such that the provided type is a .NET reference type. </div>
Define keyword: null 1. Indicates the absence of an object<div>2. Used in generic parameter constraints such that the provided type must support the null literal. </div>
Define keyword: of 1. Used in discriminated unions to indicate the type of categories of values. ex. Foo of int<div>2. Used in delegate and exception declarations. ex. exception MyError of string</div>
Define keyword: open Makes the contents of the given namespace or module available without name qualification.
Define keyword: or 1. Boolean condition operator, equivalent to ||<div>2. Member constraint such that a provided type must have a member that has the specified signature. </div>
Define keyword: override Used to implement a version of an abstract or virtual method that differs from the base version.
Define keyword: private Visibility modifier that restricts access to a member to code in the same type or module.
Define keyword: public Visibility modifier that makes access to a member available outside the type.
Define keyword: rec Used to indicate a function is recursive.
Define keyword: return Computational Expressions: used to indicate a value to provide as the result of a computation expression.
Define keyword: return! Computation expressions: indicates a computation expression that, when evaluated, provides the result of the containing computation expression.
Define keyword: select Used in query expressions - not actually a reserved word, it only acts like one in the appropriate context.
Define keyword: static Used to indicate a method or property is not specific to any particular class instance.
Define keyword: struct 1. Used to declare a structure type<div>2. Generic parameter constraints. </div><div>3. Used for OCaml compatibility in module definitions</div>
Define keyword: then 1. Conditional expressions<div>2. Used to execute expressions with side-effects within a constructor. ex. </div><div>new() = </div><div> Person("Invalid name")</div><div> then</div><div> printfn("Invalid...")</div>
Define keyword: to Used in for loops to indicate a range
Define keyword: true Boolean literal
Define keyword: try Introduces a block that might generate an exception. Used in combination with <b>with </b>or <b>finally</b>
Define keyword: type Used to declare a class, record, structure, discriminated union, enumeration type, unit of measure or type abbreviation.
Define keyword: upcast Convert to a type that is higher in the inheritance chain.
Define keyword: use Replaces let value values that require Dispose be called to free resources.
Define keyword: use! Replaces let! in asynchronous workflows and other computation expressions for values that require Dispose be called to free resources.
Define keyword: val 1. Used in a signature to indicate a value<div>2. Used in a type to declare a member in limited situations. </div>
Define keyword: void Indicates the .NET void type - used for interop with other .NET languages.
Define keyword: when 1. Boolean conditions on pattern matches<div>2. Introduces a constraint clause for a generic type parameter</div>
Define keyword: while Looping construct
Define keyword: with 1. Used with match keyword in pattern matching expressions<div>2. Used in object expressions</div><div>3. Used in record copying expressions</div><div>4. Used in type extensions to introduce member definitions and to introduce exception handlers. </div>
Define keyword: yield In a sequence expression it produces a value.
Define keyword: yield! In a computation expression, used to append the result of a given computation expression to a collection of results for the containing computation expression.
What are the reserved tokens in F# since they are OCaml? asr<div>land</div><div>lor</div><div>lsl</div><div>lsr</div><div>lxor</div><div>mod</div><div>sig</div>
What are the reserved tokens for F#? atomic<div>break</div><div>checked</div><div>component</div><div>const</div><div>constraint</div><div>continue</div><div>eager</div><div>event</div><div>external</div><div>fixed</div><div>functor</div><div>method</div><div>mixin</div><div>object</div><div>parallel</div><div>process</div><div>protected</div><div>sealed</div><div>tailcall</div><div>trait</div><div>virtual</div><div>volatile</div>