1. Home
  2. /
  3. Ocaml
  4. /
  5. Conditional Counter Increment

Conditional Counter Increment - Ocaml Typing CST Test

Loading…

Conditional Counter Increment — Ocaml Code

Increment counter only if less than 5.

let count = ref 3
if !count < 5 then count := !count + 1
let () = Printf.printf "%d\n" !count

Ocaml Language Guide

OCaml is a functional, imperative, and object-oriented programming language in the ML family. It features strong static typing, type inference, and a powerful module system, making it suitable for compiler construction, systems programming, and formal verification.

Primary Use Cases

  • ▸Compiler and interpreter development
  • ▸Formal verification and theorem proving
  • ▸High-performance and reliable software
  • ▸Financial modeling and risk analysis
  • ▸Systems and network programming

Notable Features

  • ▸Strong static type system with type inference
  • ▸Pattern matching for concise code
  • ▸Modules, functors, and polymorphic variants
  • ▸Garbage-collected runtime
  • ▸Interoperability with C and JavaScript via BuckleScript/Js_of_ocaml

Origin & Creator

Developed in 1996 by Xavier Leroy and the INRIA team in France as an extension of the Caml language.

Industrial Note

OCaml is widely used in formal methods, theorem provers (e.g., Coq), and financial software requiring high reliability.

More Ocaml Typing Exercises

OCaml Counter and Theme ToggleOCaml Simple AdditionOCaml FactorialOCaml Fibonacci SequenceOCaml Max of Two NumbersOCaml List SumOCaml Even Numbers FilterOCaml Resettable CounterOCaml Theme Toggle Only

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher