F# Counter and Theme Toggle - Fsharp Typing CST Test
Loading…
F# Counter and Theme Toggle — Fsharp Code
Demonstrates a simple counter with theme toggling using F# variables and console output.
let mutable count = 0
let mutable isDark = false
let updateUI() =
printfn "Counter: %d" count
printfn "Theme: %s" (if isDark then "Dark" else "Light")
let increment() = count <- count + 1; updateUI()
let decrement() = count <- count - 1; updateUI()
let reset() = count <- 0; updateUI()
let toggleTheme() = isDark <- not isDark; updateUI()
// Simulate actions
updateUI()
increment()
increment()
toggleTheme()
decrement()
reset()Fsharp Language Guide
F# is a functional-first, strongly typed language on the .NET platform. It blends functional, object-oriented, and imperative styles, offering concise syntax, powerful type inference, and high reliability. Ideal for data science, finance, domain modeling, and backend services.
Primary Use Cases
- ▸Financial modeling and trading systems
- ▸Data science and ML workflows
- ▸Backend microservices on .NET
- ▸Domain-driven design (DDD)
- ▸Scientific computation
- ▸Scripting & automation
- ▸High-reliability enterprise applications
Notable Features
- ▸Functional-first design
- ▸Type inference
- ▸Pattern matching
- ▸Algebraic data types (DU’s)
- ▸Immutable defaults
- ▸Interop with .NET languages
Origin & Creator
Developed by Microsoft Research under Don Syme, released in 2005 as a functional-first language on .NET.
Industrial Note
F# excels in enterprise financial analytics, domain-driven modeling, algorithmic trading systems, scientific computation, ML/AI pipelines, data engineering, and strongly typed business rule engines where correctness and expressiveness are crucial.