β All skills
Ocaml Developer
Use when building correct, performant OCaml applications with type inference, pattern matching, Dream web framework, and opam ecosystem.
About this skill
Use when building correct, performant OCaml applications with type inference, pattern matching, Dream web framework, and opam ecosystem.
SKILL.md
ocaml-developer.SKILL.mdPlace it in your Syntic skills folder. For Syntic Code, install in your local skills directory, review the contents and run it in a controlled environment first.
--- name: Ocaml Developer description: Use when building correct, performant OCaml applications with type inference, pattern matching, Dream web framework, and opam ecosystem. category: Languages version: 1.0.0 tools: [] --- # OCaml Type-Safe Development Build correct, performant applications using OCaml's powerful type system and exhaustive pattern matching. ## Type System Design - Define domain types as variants (sum types) and records (product types); make invalid states unrepresentable - Use polymorphic variants (`[`A | `B]`) for extensible types across module boundaries; regular variants for closed sets - Leverage type inference; annotate function signatures in `.mli` interface files; let compiler infer in `.ml` implementations - Use phantom types to encode constraints: `type readonly` and `type readwrite` as phantom parameters - Use GADTs for type-safe expression evaluators, serialization, protocol definitions ## Pattern Matching - Match exhaustively; compiler warns on non-exhaustive matches - Use `when` guards sparingly; extract complex guards into named functions - Use `as` bindings to capture destructured parts and whole value: `| (Point (x, y) as p) ->` - Use `or` patterns to merge cases: `| Red | Blue ->` - Use `function` keyword for single-argument pattern matching ## Module System - Define `.mli` interface files for every public module; signature is the API contract - Use functors to parameterize modules; common use case: data structures parameterized over comparison functions - Use first-class modules for runtime module selection - Organize code into libraries with `dune` `(library ...)` stanzas - Use `include M` to extend modules; use `module type of` to capture signatures ## Dream Web Framework - Define routes with `Dream.get`, `Dream.post`; group with `Dream.scope` for shared middleware - Use `Dream.param` for path parameters, `Dream.query` for query strings - Use `Dream.sql` with Caqti for typed database access via Caqti request values - Apply middleware: `Dream.logger`, `Dream.csrf`, `Dream.memory_sessions` or `Dream.sql_sessions` - Return proper status codes with `Dream.respond ~status:`; use `Dream.json` or `Dream.html` ## Error Handling & Performance - Use `Result.t` (`Ok | Error`) for recoverable errors; `Option.t` only for genuinely optional values - Define error types as variants: `type error = Not_found | Permission_denied | Validation of string` - Use `Result.bind` or `let*` operator to chain fallible operations - Use `Array` for random access; `List` for sequential processing - Profile with `landmarks` or `perf` integration; use `Core_bench` for micro-benchmarks - Use Flambda compiler optimizations (`-O3 -flambda`) for release builds ## Build & Tooling - Use `dune` as build system; define `dune-project` at root with `(lang dune 3.x)` - Use `opam` for dependency management; pin production dependencies to exact versions - Use `ocamlformat` for consistent formatting; configure in `.ocamlformat` - Use `merlin` for IDE integration ## Before Completing - Run `dune build @all` with zero warnings - Run `dune runtest` to execute all tests - Run `ocamlformat --check` on all source files - Verify `.mli` files expose only intended public API
Install
Syntic App
- 1Create a dedicated folder for this skill in your local skills library.
- 2Place SKILL.md into that folder.
- 3Restart Syntic and invoke this skill on matching tasks.
Syntic Code (CLI)
- 1Save SKILL.md in your local Syntic Code skills directory.
- 2Keep related files in the same skill folder.
- 3Run in a safe environment and validate outputs.