Counter and Theme Toggle - Ocaml Typing CST Test
Loading…
Counter and Theme Toggle — Ocaml Code
Demonstrates a simple counter with theme toggling using OCaml references and functions.
let count = ref 0
let isDark = ref false
let updateUI () =
Printf.printf "Counter: %d\n" !count;
Printf.printf "Theme: %s\n" (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 ();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.