Interview :: F#
What is a try-with block in F#?
In F#, you can create a user-defined exception. It provides flexibility to define custom exceptions according to requirement.
EXAMPLE
What is FailWith and InvalidArg in F#?
In F#, you can throw exceptions explicitly. You are allowed to throw a custom exception. You can also throw exceptions by using predefined methods of Exception like Failwith and InvalidArgs.
Example of FailWith keyword
Example of InvalidArg keyword
The assert expression is a debugging feature of F#. You can use it to test an expression. It generates a system error dialog box upon failure in Debug mode.
Example
The Module is a collection of classes, functions, and types. It helps to organize related code so we can maintain code easily.
Example
Access control specifies the accessibility of code. By using these, you can specify the scope of data, method, class, etc.
There are 3 types of access control in F#.
- Public: Public access control also known as default. It is accessible for all. If you don't specify any access control explicitly in your code, by default it follows public access control.
- Private: F# provides private keyword to declare private members in the class or type. The scope of private is limited to the local block in which it is declared.
- Internal: Internal access control is only accessible from the same assembly. An assembly is a file which is automatically generated by your compiler after compilation of F# code.
F# manages resources with the help of use and using keywords. Resources may be data, a file or network, etc. It acquires a resource from the operating system or other service providers so that it can be provided to other application.
Example
In F#, the attribute is used to enable metadata for a program code construct. The attribute can be applied to any construct like function, module, method, and type.
Example
In F#, the signature file contains information about the public signatures. Signatures can be of a set of program elements, such as types, namespaces, and modules.
Signature file named as signature.fsi
An import declaration specifies a module or namespace. You can reference its elements without using a fully qualified name.
Example
The 'base' keyword is used as the name of the base class object.