Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Things to know about F# before getting started and mutable variables

2009-08-28

F# is a .NET enabled functional programming language that has features that you would expect such a language to have (lists, tuples, pattern matching and so on), as well as the features you would expect from a .NET language such as preemptive multitasking, dynamic linking and Unicode strings. The program starts from the top of your source file instead of in a main function (as C# or Visual Basic), and the language is case sensitive, like C#. The editor support in Visual Studio 2008 slightly more limited than for C# or Visual Basic; you can still work with breakpoints and the locals window but perhaps not with code suggestions or code tips.
This example creates an integer, initialized with the value 10, and prints it out:

let x = 10
printfn "x=%d" x

If I wanted to assign a new value to x like below (complete source is shown, not just changes), a compile error will occur, telling me that x is not mutable – it can not change it’s value.

let x=10
printfn "x=%d" x
x <- 11
printfn "x=%d" x

The keyword mutable at declaration, gives x the capability to chainge.

let mutable x=10
printfn "x=%d" x
x <- 11
printfn "x=%d" x

Categories: Microsoft .NET

Tags: F#

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips