1. Home
  2. /
  3. Fsharp
  4. /
  5. F# Simple Calculator

F# Simple Calculator - Fsharp Typing CST Test

Loading…

F# Simple Calculator — Fsharp Code

Demonstrates basic arithmetic operations using functions.

let add a b = a + b
let subtract a b = a - b
let multiply a b = a * b
let divide a b = a / b

printfn "Add 5 + 3: %d" (add 5 3)
printfn "Subtract 5 - 3: %d" (subtract 5 3)
printfn "Multiply 5 * 3: %d" (multiply 5 3)
printfn "Divide 6 / 2: %d" (divide 6 2)

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.

More Fsharp Typing Exercises

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

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher