what are comments in F# language? How do you write a comment in F#?
Comments are a string of code statements. Comments are for programmers and developers, not for a F# Compiler. These are ignored at runtime.
F# supports two types of comments
- Single Line Comments
- Multi-Line or Block Comments
- Documentation Comments
How to write a comment in F# language?
To write a Single line comment, Please follow the below steps
Single-line comments contain a string in a single line, always starts with //
// single line comments example
printfn "Hello World"
To write a block comment, Please follow the below steps.
Block comments are multi-line comments that span multiple lines
comments start with (*
followed by comment string in multiple lines, ends with *)
(*
hello.fs
multi-line comments example
*)
printfn "Hello World"
Documentation comments in F
Documentation comments are helpful for developers to understand Code API.
Documentation comments always start with ///
followed by documentation tags
Here is an example
/// Employee type
type Employee =
val name : string
/// <summary></summary>
/// <param name="name">Name. name of an employee.</param>
new (name) = { name = name }
Above example, contains
- documentation comments started with triple slashes
<summary>
tag is a description of the line of code<params>
tag contains parameters for a constructor
It generates the following XML on running the documentation generator compiler.
<name name="M:Employee.#ctor(System.String)">
<summary>
Class constructor.
</summary>
<params>
Name. name of an employee
</params>
</name>