Interview :: F#
Binding is a process of associating of identifier or function to a value. Let keyword is used to bind an identifier to a value. In F#, We use let keyword to declare variable, function and private class members.
F# Let binding in function
We use let keyword to define a function in F#.
What is "do bindings" in F#?
Do binding is used to execute code without defining a function or any type. You can write independent code by using do binding in F#.
EXAMPLE
What is type annotation in F#?
F# allows type annotation so that you can explicitly mention the type of identifier or parameter or return type of a function. You must use: (colon) to apply annotation in F#.
EXAMPLE
What is Type Inference in F#?
Type inference means when you are writing code then you don't need to specify the type of values or variables. F# compiler is strong enough to infer the type of value.
EXAMPLE
When code does not specify any type explicitly, then the compiler considers generic type. It is called an automatic generalization. It helps to write generic code without increasing complexity.
In F#, tuples are a collection of anonymous values. Values may be the same or different types. It allows us to put expression as a value also.
Example
Yes, by using a tuple, you can return multiple values in a function.
Example
It is an immutable collection of same type elements. It maintains the order of elements.
F# List Example
Arrays are mutable collections of data of the same type. It starts from index 0 and goes to n-1 where n is the length of arrays.
Example
What is Sequence in F#?
The Sequence is a series of the same type of elements. It provides better performance than list.
Example
You can create sequence expression like following. Here, we have used Seq.iter () function to iterate sequence. We can also use for loop or array format specifier to iterate sequence elements.