ocaml
/ocaml
Pomaga w programowaniu funkcyjnym w OCaml: algebraiczne typy danych, dopasowanie wzorców, moduły i Dune, przy narzędziach do analizy statycznej, kompilatorach i oprogramowaniu wysokiej niezawodności.
- Autor
- G1Joshi ↗
- Repozytorium
- Agent-Skills ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 01.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 1
Brak sygnałów. Repozytorium zmienione 01.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pomaga w programowaniu funkcyjnym w OCaml: algebraiczne typy danych, dopasowanie wzorców, moduły i Dune, przy narzędziach do analizy statycznej, kompilatorach i oprogramowaniu wysokiej niezawodności.
Oryginalny opis (EN)
Expert OCaml functional programming assistance covering algebraic data types, pattern matching, modules, and Dune. Use when developing static analysis tools, compilers, theorem provers, or high-assurance software.
Jak działa
- When to Use
- Quick Start
- Core Concepts
- Common Patterns
- Best Practices
- Troubleshooting
- References
Podgląd SKILL.md
---
name: ocaml
description: Expert OCaml functional programming assistance covering algebraic data types, pattern matching, modules, and Dune. Use when developing static analysis tools, compilers, theorem provers, or high-assurance software.
---
# OCaml
OCaml v5 brings **Multicore** support to the language, removing the Global Interpreter Lock (GIL). It combines functional safety with imperative speed.
## When to Use
- **High-Performance Static Functional Programming**: Writing safe, algebraic, strongly-typed systems running at near-C execution speeds.
- **Financial Trading Platforms (Jane Street)**: Building mission-critical quantitative trading infrastructure and order books.
- **Static Analysis & Formal Verification Tools**: Authoring compilers, linters, and verification suites (Coq, Flow, Infer).
- **Multicore Parallelism (OCaml 5)**: Leveraging OCaml 5's native multicore concurrency, domains, and effect handlers.
## Quick Start
```ocaml
(* Define a recursive binary tree and compute depth *)
type 'a tree =
| Leaf
| Node of 'a * 'a tree * 'a tree
let rec depth = function
| Leaf -> 0
| Node (_, left, right) -> 1 + max (depth left) (depth right)
let my_tree = Node ("root", Node ("left", Leaf, Leaf), Leaf)
let () = Printf.printf "Tree depth: %d\n" (depth my_tree)
```
## Core Concepts
### Hindley-Milner Type Inference & Pattern Matching
Infers static types globally without requiring verbose type annotations:
```ocaml
(* Algebraic Data Type with Exhaustive Pattern Matching *)
type payment_status =
| Pending of float
| Completed of { id: string; amount: float }
| Failed of string
let summarize_payment = function
| Pending amount -> Printf.sprintf "Pending charge of $%.2f" amount
| Completed { id; amount } -> Printf.sprintf "Completed #%s: $%.2f" id amount
| Failed reason -> Printf.sprintf "Failed: %s" reason
```
### Module System (Signatures & Functors)
Powerful structural module system supporting parameterized modules (Functors):
```ocaml
module type COMPARABLE = sig
type t
val compare : t -> t -> int
end
(* Functor generates a Set for any comparable type *)
module MakeSet (Item : COMPARABLE) = struct
type element = Item.t
(* Internal balanced tree implementation *)
end
```
### OCaml 5 Effect Handlers & Multicore Domains
Native CPU domain parallelism and structured non-blocking effects:
```ocaml
open Domain
let task1 = spawn (fun () -> Array.fold_left (+) 0 (Array.make 1_000_000 1))
let task2 = spawn (fun () -> Array.fold_left (+) 0 (Array.make 1_000_000 2))
let total = join task1 + join task2
```
## Common Patterns
### Modular Architecture with Functors
**Problem**: Writing generic container algorithms independent of concrete key comparison logic.
**Solution**:
Use OCaml Functors (modules parameterized by modules):
```ocaml
module type Comparable = sig
type t
val compare : t -> t -> int
end
module MakeSet (Item : Comparable) = struct
type element = Item.t
type t = element list
let empty = []
let rec insert x = function
| [] -> [x]
| h :: t as l ->
let c = Item.compare x h in
if c = 0 then l
else if c < 0 then x :: l
else h :: (insert x t)
end
```
## Best Practices
**Do**:
- Use Dune as Standard Build System: Build, test, and manage projects exclusively using `dune build` and `dune runtest`.
- Adopt OCaml 5+: Utilize modern Multicore OCaml with concurrent Domain execution.
- Leverage Jane Street Base & Core: Enhance the standard library using battle-tested `Base` and `Core`.
- Enforce Exhaustive Pattern Matching: Address all compiler warnings (`-w +A`) regarding unhandled pattern cases.
**Don't**:
- Use polymorphic equality (`=`) carelessly: Polymorphic equality can crash at runtime on functional closures; use typed comparators.
- Rely on unhandled exceptions for control flow: Represent failure explicitly using `Result.t` or `Option.t`.
- Mutate state across Domains without synchronization: Use atomic variables (`Atomic.t`) when sharing memory between threads.
## Troubleshooting
| Error | Cause | Solution |
| :------------------------------------------------------------------------------- | :---------------------------------------------------------- | :-------------------------------------------------------------------- |
| `Error: This expression has type ... but an expression was expected of type ...` | Type mismatch in expression. | Check function argument order; OCaml does not perform implicit casts. |
| `Warning 8 [partial-match]: this pattern-matching is not exhaustive` | Pattern matching missing one or more cases. | Add missing match cases to ensure all possibilities are handled. |
| `Error: Unbound module ...` | Module not installed or missing in Dune `libraries` stanza. | Add library dependency to `dune` file and run `dune build`. |
## References
- [OCaml.org](https://ocaml.org/)
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · G1Joshi/Agent-Skills | 100 | MIT |
| avsm/ocaml-claude-marketplace | 100 | ISC |
Migawka bazy z 13.11.2026 · wersja paczki 63512fb0d615 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100dune-migration
Pomaga migrować projekty OCaml z ocamlbuild i topkg na dune: pliki _tags, .mllib, pkg/pkg.ml i zmiana systemu budowania. - 100ocaml-docs
Naprawia ostrzeżenia i błędy dokumentacji odoc w OCaml: dune build @doc, składnia referencji, odwołania między pakietami, niejednoznaczne referencje, ukryte pola i tagi @raise. - 100fsharp
Pomaga w programowaniu funkcyjnym w F#: dopasowanie wzorców, niemutowalność, workflow async i współpraca z .NET, przy modelach domeny, potokach danych i usługach chmurowych. - 85Gleam Type System
Omawia system typów Gleam: typy algebraiczne i własne, dopasowanie wzorców, typy generyczne, inferencję, typy opaque, sprawdzanie wyczerpywalności i obsługę błędów w stylu funkcyjnym. - 100haskell
Wspiera pracę z Haskellem: czyste programowanie funkcyjne, monady, klasy typów, GHC oraz Cabal i Stack, przy tworzeniu dowodliwie poprawnego oprogramowania, kompilatorów i modeli finansowych. - 85Scala Functional Patterns
Omawia wzorce programowania funkcyjnego w Scali: funkcje wyższego rzędu, niemutowalność, dopasowanie wzorców, typy algebraiczne, monady, for-comprehensions i kompozycję funkcji.