F Sharp (programming language): Difference between revisions

Content deleted Content added
Shr2012 (talk | contribs)
Shr2012 (talk | contribs)
Line 573:
printfn "Hello World!"
</syntaxhighlight>
A record type definition. Records are immutable by default and are compared by structural equality.
 
<syntaxhighlight lang="fsharp">
type Person = {
FirstName: string
LastName: string
Age: int
}
 
// Creating an instance of the record
let person = { FirstName = "John"; LastName = "Doe"; Age = 30 }
</syntaxhighlight>
 
 
A Person class with a constructor taking a name and age and two immutable properties.
Line 608 ⟶ 621:
let printList lst =
for x in lst do
printfn $"%d{x}" x
 
/// Iteration using a higher-order function
Line 625 ⟶ 638:
<syntaxhighlight lang="fsharp">
/// Fibonacci Number formula
[<TailCall>]
let fib n =
let rec g n f0 f1 =