1. Simple values: functions, parameters, and top-level items defined using let or pattern matching.
Examples: form, text, wordcount.
Simple value: functions, parameters and top-level member definitions are implemented using let or pattern matching.
Code
Let Form = New Form ()
Let Highlow a B =
Match (A, B) With
| ( " Lo " , LO ),( " Hi " , Hi) -> (Lo, hi)
| ( " Hi " , Hi ),( " Lo " , LO) -> (Lo, hi)
2. methods: function values associated with types. interfaces, classes, and record and Union types can all have associated methods. methods can be overloaded (see chapter 6) and must be applied immediately to their arguments.
Examples: system. net. webrequest. Create and resp. getresponsestream.
Method: type-related function value. Interfaces, classes, records, and Union types can all have related methods. Methods can be overloaded, and they must be assigned parameters.
3. properties: A shorthand for invoking method members that read or write underlying data. interfaces, classes, and record and Union types can all have associated properties. examples: system. datetime. now and form. topmost.
Attribute: a shortcut for calling a member function to read and write values. Interfaces, classes, records, and Union types can all have associated attributes. We can use the <-operator to assign values.
Code
Form. Text <- " Form1 "
4. indexer properties: A property can take arguments, in which case it is an indexer property. indexer properties named item can be accessed using. [_] syntax. examples: vector. [3] and matrix. [3, 4].
Attribute indexer: an attribute with parameters. Here it is an attribute indexer. You can use. [_] to access the named property indexer.
In addition, we encountered a problem today, that is, how to use F # To sum the series. For example, if we enter a value of 100 and calculate the numbers from 1 to 100, if we use the C/C ++ language to write
Code
Int Accumulate ( Int N)
{
Int Result = 0 ;
For ( Int I = 0 ; I < N; I ++ )
{
Result = Result + I;
}
ReturnResult;
}
IfCodeTranslate directly into F #ProgramIt looks like this.
Code
Let Accumulate (N: Int ) =
Let Mutable Result = 0
Let Mutable I = N
While I> 0 Do
Result <- Result + I
I <- I- 1
(Result)
However, mutable variables are not recommended in F #, so a better method is to use recursive functions.
Code
Let REC Accumulate1 (N: Int ) =
If N <= 1 Then 1 Else N + accumulate1 (n- 1 )
As for the optimization method, I haven't thought of it yet.