1. Home
  2. /
  3. Fsharp Typing Test
  4. /
  5. F# Counter and Theme Toggle

F# Counter and Theme Toggle - Fsharp Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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()
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

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.

Quick Explain

  • ▸F# is functional-first but supports OOP and imperative features.
  • ▸Runs on .NET, giving access to the entire .NET ecosystem.
  • ▸Popular in finance, data engineering, scientific computing, and reliable backend services.

Core Features

  • ▸Expressions over statements
  • ▸Powerful type inference
  • ▸Discriminated unions
  • ▸Pattern matching everywhere
  • ▸Pipelining with
  • ▸Async workflows

Learning Path

  • ▸Functional thinking basics
  • ▸DU’s, records, modules
  • ▸Pipelines & pattern matching
  • ▸Async workflows
  • ▸Domain modeling & DDD

Practical Examples

  • ▸Domain modeling with DU’s
  • ▸Financial risk calculator
  • ▸Async HTTP service
  • ▸Data pipeline workflow
  • ▸ML.NET model integration

Comparisons

  • ▸More concise than C#
  • ▸More enterprise-ready than Python
  • ▸More type-safe than JavaScript
  • ▸Less concurrency-focused than Elixir
  • ▸More accessible tooling than Haskell

Strengths

  • ▸Concise & expressive code
  • ▸Enterprise-grade reliability on .NET
  • ▸Strong static typing with inference
  • ▸Excellent for domain modeling
  • ▸Great for data processing & analysis

Limitations

  • ▸Smaller community than C#/Python
  • ▸Not ideal for UI-heavy applications
  • ▸Learning curve for functional thinking
  • ▸Corporate teams often prefer C#
  • ▸Tooling is improving but not perfect

When NOT to Use

  • ▸Frontend UI-heavy apps
  • ▸Games requiring Unity/C# workflow
  • ▸Projects with large C#-only teams
  • ▸Tiny scripts (Python is simpler)
  • ▸GPU-heavy ML workloads

Cheat Sheet

  • ▸Record: type Person = { Name: string; Age: int }
  • ▸DU: type Shape = Circle of float
  • ▸Match: match x with
  • ▸Pipe: x
  • ▸Async: async { let! r = fetch(); return r }

FAQ

  • ▸Is F# used in industry?
  • ▸Yes-especially in finance, modeling, and enterprise systems.
  • ▸Is F# only functional?
  • ▸No-functional-first but supports OOP & imperative code.
  • ▸Is F# better than C# for some tasks?
  • ▸Yes-functional modeling, data pipelines, and correctness-heavy logic.
  • ▸Is F# good for beginners?
  • ▸Yes-concise syntax and strong type inference help beginners a lot.

30-Day Skill Plan

  • ▸Week 1: Syntax, lists, functions
  • ▸Week 2: DU’s, records, modules
  • ▸Week 3: Async workflows, data pipelines
  • ▸Week 4: Real-world app + DDD

Final Summary

  • ▸F# is a powerful functional-first language on .NET.
  • ▸It is ideal for finance, data pipelines, scientific computation, and enterprise architecture.
  • ▸Its expressive type system and concise syntax make modeling complex domains easy.
  • ▸F# combines functional elegance with industrial-grade performance.

Project Structure

  • ▸Program.fs (entry point)
  • ▸Library modules in separate .fs files
  • ▸.fsproj config
  • ▸paket.dependencies / nuget
  • ▸tests/ folder

Monetization

  • ▸Financial engineering roles
  • ▸Data science consulting
  • ▸SaaS backend development
  • ▸Algorithmic trading systems

Productivity Tips

  • ▸Use pipelines aggressively
  • ▸Model domains with DU’s
  • ▸Use REPL for rapid exploration
  • ▸Use records for clarity

Basic Concepts

  • ▸Immutability
  • ▸Discriminated unions
  • ▸Record types
  • ▸Sequences, lists, arrays
  • ▸Pattern matching
  • ▸Pipelines & higher-order functions

Official Docs

  • ▸F# Official Documentation
  • ▸.NET API Browser
  • ▸F# Software Foundation

More Fsharp Typing Exercises

F# Simple CalculatorF# FactorialF# Fibonacci SequenceF# List ComprehensionF# Map FilteringF# Anonymous FunctionsF# Reduce ExampleF# Zip and MapF# Pattern Matching on Tuples

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher