1. Home
  2. /
  3. Ocaml
  4. /
  5. List Sum

List Sum - Ocaml Typing CST Test

Loading…

List Sum — Ocaml Code

Sums elements of a list recursively.

let rec sum_list lst = match lst with [] -> 0 | x::xs -> x + sum_list xs
let () = Printf.printf "%d\n" (sum_list [1;2;3;4;5])

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 Even Numbers FilterOCaml Conditional Counter IncrementOCaml Resettable CounterOCaml Theme Toggle Only

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher