OCaml

1 program Added 2025-10-22T09:34:41Z Model: anthropic/claude-3.5-sonnetTemp: 0.4 Evidence Report issue View issues
Aliases: Objective Caml, OCaml
Provenance: commit 567c25d0a4 · authored 2025-10-22T11:34:41+02:00 · model anthropic/claude-3.5-sonnet

Sources mentioning this language

8 sources · pl_id: pl/ocaml
LLM (this repo) · 1PldbLinguistPygmentsWikipediaHyperpolyglotRosettacodeWikidata · Q212587

Wikipedia infobox

Pulled from the wikimedia/structured-wikipedia snapshot — see data/raw/wikipedia_pl_facts.*.jsonl and pl_fact.csv for the long-table provenance.

Paradigmsmulti-paradigm: functional · imperative · modular · object-oriented
Typinginferred, static, strong, structural
Designed byInria · Xavier Leroy · Jérôme Vouillon · Damien Doligez · Didier Rémy · Ascánder Suárez
First appeared1996
Influenced byC · Caml · Modula-3 · Pascal · Standard ML
LicenseLGPLv2.1
Implemented inOCaml · C
Homepagehttps://ocaml.org/

Extensions claimed by this language

13 claims. Each row is one upstream assertion with its strength. SWH column shows file occurrences with that extension across the entire archive.
ExtensionSourceStrengthSWH
.mllinguistprimary5.2M files
.mlpygmentsprimary5.2M files
.mlwikidataprimary5.2M files
.mliwikidataprimary974.6K files
.eliomlinguistsecondary17.1K files
.eliomilinguistsecondary2.5K files
.ml4linguistsecondary15.1K files
.mlilinguistsecondary974.6K files
.mlipygmentssecondary974.6K files
.mlllinguistsecondary76.2K files
.mllpygmentssecondary76.2K files
.mlylinguistsecondary108.1K files
.mlypygmentssecondary108.1K files

Related languages

Objective Caml (1.00)Objective-C (0.37)Objective-J (0.35)Objective-C++ (0.30)ObjectIcon (0.29)

LLM-contributed programs

Simple OCaml Calculator

Provenance: commit 567c25d0a4 · authored 2025-10-22T11:34:41+02:00 · model anthropic/claude-3.5-sonnet · Temp 0.4
code.ml · license: LGPL-2.1 · added: 2025-10-22T09:34:41Z
type token = Plus | Minus | Times | Div | Num of int | Lparen | Rparen

let rec expr = parser
  | [< x = term; e = expr_cont >] -> e x
and expr_cont = parser
  | [< 'Plus; x = term; e = expr_cont >] -> (fun y -> e (x + y))
  | [< 'Minus; x = term; e = expr_cont >] -> (fun y -> e (x - y))
  | [< >] -> (fun x -> x)
and term = parser
  | [< x = fact; t = term_cont >] -> t x
and term_cont = parser
  | [< 'Times; x = fact; t = term_cont >] -> (fun y -> t (x * y))
  | [< 'Div; x = fact; t = term_cont >] -> (fun y -> t (x / y))
  | [< >] -> (fun x -> x)
and fact = parser
  | [< 'Num x >] -> x
  | [< 'Lparen; x = expr; 'Rparen >] -> x

Real programs from Software Heritage

3 samples mined from derived_datasets/<date>/contents/*.parquet, byte-verified against the SWH archive. Citation-grade qualified SWHIDs preserved.
logs_sequence_number.mli · 127 B · ext .mli · seen 154× in SWH
via fallback
swh:1:cnt:57a5de4f61ddd67d42223b478a56df3f52460edb;origin=https://github.com/Nitrokey/nethsm;anchor=swh:1:rev:0730aa85338b227a8be5f9a42b8477948041fc26;path=/src/keyfender/logs_sequence_number.mli
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
(* Copyright 2023 - 2023, Nitrokey GmbH
   SPDX-License-Identifier: EUPL-1.2
*)

val reporter : Logs.reporter -> Logs.reporter
boa_skeleton.eliom · 1457 B · ext .eliom · seen 13× in SWH
via fallback
swh:1:cnt:e2668403fdb66bf914dec4e058d889bd1a36a87f;origin=https://github.com/xvw/hhd-ghost;anchor=swh:1:rev:d4d3b430ddbe37ea6027a7463cf638b7b42bf026;path=/app/boa_skeleton.eliom
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
open Eliom_content
open Html5.D

module type Skeleton =
  sig

    val css_files : string list list
    val js_files : string list list
    val other_header : Html5_types.head_content_fun Html5.elt list
  end

    
module Make (F : Skeleton) =
  struct 

    let raw title content =
      Eliom_tools.F.html
        ~title:title
        ~css:F.css_files
        ~js:F.js_files
        ~other_head:([
          meta
            ~a:[
              a_name "viewport";
              a_content "width = device-width"
            ] ()
        ]@F.other_header)
        (Html5.F.body content)
        
    let return title content =
      raw title content
      |> Lwt.return
                      
  end

module Base : Skeleton =
  struct

    let js_files = []
    let css_files =
      [
        ["css"; "knacss.css"];
        ["css"; "constrictor.css"];
        ["css"; "boa.css"];
        ["css"; "ghost.css"];
      ]
    let other_header = []
  end

include Make(Base)

module MBBase : Skeleton =
  struct

    let css_files = Base.css_files  
    let js_files = []
    let other_header =
      [
        css_link
          ~uri:(
            Raw.uri_of_string
              "https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.css"
          ) ();
        js_script
          ~uri:(
            Raw.uri_of_string
              "https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.js"
          ) ();
        
      ]
  end

module Mapbox = Make(MBBase)
WLexer.mll · 5496 B · ext .mll · seen 8× in SWH
via fallback
swh:1:cnt:fafc17d5429e60f2f6d7b11293daaaa202e714a9;origin=https://github.com/GillianPlatform/Gillian;anchor=swh:1:rev:9ca68ac1a24bf58fa501067419808a5531365b89;path=/wisl/lib/ParserAndCompiler/WLexer.mll
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
{
  open Lexing
  open CodeLoc
  open WParser

  exception SyntaxError of string
  let l_start_string = ref CodeLoc.dummy
}


let digit = ['0'-'9']
let letter = ['a'-'z''A'-'Z']
let gvars = "gvar_" digit+ (* generated variables during compilation *)
let identifier = letter(letter|digit|'_')*
let lvar = '#' (letter|digit|'_'|'$')*
let integer = digit+
let float = digit* '.' digit*
let loc = "$l" (letter|digit|'_')*
let white = [' ' '\t']+
let newline = '\r' | '\n' | "\r\n"

rule read =
  parse
  (* keywords *)
  | "@config" { CONFIG (curr lexbuf) }
  | "true"   { TRUE (curr lexbuf) }
  | "false"  { FALSE (curr lexbuf) }
  | "nil"    { LSTNIL (curr lexbuf) }
  | "null"   { NULL (curr lexbuf) }
  | "while"  { WHILE (curr lexbuf) }
  | "if"     { IF (curr lexbuf) }
  | "else"   { ELSE (curr lexbuf) }
  | "skip"   { SKIP (curr lexbuf) }
  | "fresh"  { FRESH (curr lexbuf) }
  | "new"    { NEW (curr lexbuf) }
  | "free"   { DELETE (curr lexbuf) }
  | "dispose"{ DELETE (curr lexbuf) }
  | "function" { FUNCTION (curr lexbuf) }
  | "par"    { PAR (curr lexbuf) }
  | "predicate" { PREDICATE (curr lexbuf) }
  | "invariant" { INVARIANT (curr lexbuf) }
  | "return" { RETURN (curr lexbuf) }
  | "fold"   { FOLD (curr lexbuf) }
  | "package" { PACKAGE (curr lexbuf) }
  | "unfold" { UNFOLD (curr lexbuf) }
  | "nounfold" { NOUNFOLD (curr lexbuf) }
  | "apply"  { APPLY (curr lexbuf) }
  | "assert" { ASSERT (curr lexbuf) }
  | "assume" { ASSUME (curr lexbuf) }
  | "assume_type" { ASSUME_TYPE (curr lexbuf) }
  | "with" { WITH (curr lexbuf) }
  | "variant" { VARIANT (curr lexbuf) }
  | "statement" { STATEMENT (curr lexbuf) }
  | "proof"  { PROOF (curr lexbuf) }
  | "lemma"  { LEMMA (curr lexbuf) }
  | "forall" { FORALL (curr lexbuf) }
  | "bind" { EXIST (curr lexbuf) }
  | "spec" { SPEC (curr lexbuf) }
  (* types *)
  | "List" { TLIST (curr lexbuf) }
  | "Int" { TINT (curr lexbuf) }
  | "Bool" { TBOOL (curr lexbuf) }
  | "String" { TSTRING (curr lexbuf) }
  | "Float" { TFLOAT (curr lexbuf) }
  (* strings and comments *)
  | '"'      { let () = l_start_string := curr lexbuf in
               read_string (Buffer.create 17) lexbuf }
  | "//"     { read_comment lexbuf }
  (* logical binary stuff *)
  | "-*"     { WAND }
  | "->"     { ARROW }
  | "-b>"   { BLOCK_ARROW }
  | "/\\"    { AND }
  | "\\/"    { OR }
  (* punctuation *)
  | "-{"     { SETOPEN (curr lexbuf) }
  | "}-"     { SETCLOSE (curr lexbuf) }
  | "[["     { LOGOPEN (curr lexbuf) }
  | "]]"     { LOGCLOSE(curr lexbuf) }
  | '['      { LBRACK (curr lexbuf) }
  | ']'      { RBRACK (curr lexbuf) }
  | '{'      { LCBRACE (curr lexbuf) }
  | '}'      { RCBRACE (curr lexbuf) }
  | '('      { LBRACE (curr lexbuf) }
  | ')'      { RBRACE (curr lexbuf) }
  | ":="     { ASSIGN (curr lexbuf) }
  | ':'      { COLON (curr lexbuf) }
  | ','      { COMMA (curr lexbuf) }
  | "."      { DOT (curr lexbuf) }
  | ';'      { SEMICOLON (curr lexbuf) }
  | "|-"     { VDASH (curr lexbuf) }
  (* binary operators *)
  | "::"     { LSTCONS }
  | '@'      { LSTCAT }
  | "=="     { EQUAL }
  | ">="     { GREATEREQUAL }
  | '>'      { GREATERTHAN }
  | '<'      { LESSTHAN }
  | "<="     { LESSEQUAL }
  | "f>="    { FGREATEREQUAL }
  | "f>"     { FGREATERTHAN }
  | "f<"     { FLESSTHAN }
  | "f<="    { FLESSEQUAL }
  | '+'      { PLUS }
  | '-'      { MINUS }
  | '*'      { TIMES }
  | '/'      { DIV }
  | '%'      { MOD }
  | "f+"     { FPLUS }
  | "f-"     { FMINUS }
  | "f*"     { FTIMES }
  | "f/"     { FDIV }
  | "f%"     { FMOD }
  | "&&"     { AND }
  | "||"     { OR }
  | "!="     { NEQ }
  | "lnth"   { LSTNTH }
  (* unary operators *)
  | "emp"    { EMP (curr lexbuf) }
  | "len"    { LEN (curr lexbuf) }
  | "hd"     { HEAD (curr lexbuf) }
  | "tl"     { TAIL (curr lexbuf) }
  | "rev"    { REV (curr lexbuf) }
  | "sub"    { SUB (curr lexbuf) }
  | '!'      { NOT (curr lexbuf) }
  (* identifiers *)
  | white    { read lexbuf }
  | newline  { new_line lexbuf; read lexbuf }
  | float    { FLOAT (curr lexbuf, float_of_string (Lexing.lexeme lexbuf)) }
  | integer   { INTEGER (curr lexbuf, int_of_string (Lexing.lexeme lexbuf)) }
  | gvars    { IDENTIFIER (curr lexbuf, (Lexing.lexeme lexbuf)^"_user") } (* if it has a name of generated var, we add _user *)
  | identifier { IDENTIFIER (curr lexbuf, Lexing.lexeme lexbuf) }
  | lvar       { LVAR (curr lexbuf, Lexing.lexeme lexbuf) }
  | _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf)) }
  | eof      { EOF }

and read_string buf =
  parse
  | '"'       { let lend = curr lexbuf in
                let loc = merge (!l_start_string) lend in
                STRING (loc, Buffer.contents buf) }
  | '\\' '/'  { Buffer.add_char buf '/'; read_string buf lexbuf }
  | '\\' '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf }
  | '\\' 'b'  { Buffer.add_char buf '\b'; read_string buf lexbuf }
  | '\\' 'f'  { Buffer.add_char buf '\012'; read_string buf lexbuf }
  | '\\' 'n'  { Buffer.add_char buf '\n'; read_string buf lexbuf }
  | '\\' 'r'  { Buffer.add_char buf '\r'; read_string buf lexbuf }
  | '\\' 't'  { Buffer.add_char buf '\t'; read_string buf lexbuf }
  | [^ '"' '\\']+
    { Buffer.add_string buf (Lexing.lexeme lexbuf);
      read_string buf lexbuf
    }
  | _ { raise (SyntaxError ("Illegal string character: " ^ Lexing.lexeme lexbuf)) }
  | eof { raise (SyntaxError ("String is not terminated")) }

and read_comment =
  parse
  | newline { new_line lexbuf; read lexbuf }
  | eof     { EOF }
  | _       { read_comment lexbuf }

Disambiguation rules

Linguist heuristic rules that predict this language when one of its claimed extensions is shared with another.
RuleExtKindPredicates (truncated)
h/linguist/.ml/0.mlpredicates[{"kind": "any", "regexes": ["(^\\s*module)|let rec |match\\s+(\\S+\\s)+with"]}]

Contribute — propose a file extension

Tell us where to find evidence about OCaml (mapped to pl/ocaml). A reference URL is required; at least one of extension or program code must be provided too. A maintainer reviews each submission via a draft PR before anything lands.
Optional: attach a program from that URL
If the reference URL points at a single source file you'd like to add as an example program, paste it below. The workflow will write it under languages/OCaml/programs/<sha>/. Keep under ~200 lines.
(or open the pre-filled issue directly)
← Obython OcamlDuce →