writing-elm
Skill2 starsChanged 4 months agoMITView on GitHub
Write, test, review or debug Elm code, elm.json projects and Elm builds. Covers the Elm compiler from nixpkgs, offline Nix builds with elm-test-rs and elm-review, domain modeling, The Elm Architecture at scale, JSON decoder traps, JavaScript interop, rendering performance and the compile errors agents commonly hit. Use for Elm source, elm.json, elm-test/elm-review setup or Elm packaging; not merely for serving an already-built Elm bundle.
In this repository34 other files it gives its agents.
- capture-collaboration-evidenceSkill
- clarify-before-buildingSkill
- cross-platform-project-build-archSkill
- deep-code-reviewSkill
- dispatchSkill
- erect-agent-stackSkill
- fix-zig-deps-hashSkill
- gather-project-intentionsSkill
- handoffSkill
- hulk-bug-handoffSkill
- i18nSkill
- llvm-guided-optimizationSkill
- mechatron-ciSkill
- memoriesSkill
- mficSkill
- multi-implementation-contractsSkill
- no-ai-slopSkill
- onboardSkill
- performance-profilingSkill
- planning-workSkill
- scaffold-zig-projectSkill
- ship-itSkill
- test-isolationSkill
- universal-app-frontendSkill
- upgrading-zig-16-to-17Skill
- walking-decisionsSkill
- writing-bendSkill
- writing-leanSkill
- writing-nixSkill
- writing-rocSkill
- writing-rustSkill
- writing-webassemblySkill
- writing-zigSkill
- zig-microbenchmarksSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 20
Read elm.json ("elm-version" and dependencies) and the project's Nix pin before changing anything.
- Very specific: line 81
Keep structured errors such as Http.Error in the model and render them in view, rather than flattening them to strings in update.
- Distinctive: line 94
Read architecture for scaling an app, effects, interop, rendering performance and testing.
- Very specific: line 133
Do not build nested "components" with their own Model/Msg/update by default.
- Very specific: line 156
Read mistakes for the full catalog with causes and fixes: numeric types, comparable keys, recursion depth, DOM pitfalls, interop and …
- Very specific: line 162
Add packages with elm install author/package, including packages that are already indirect dependencies but are now imported directly.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing Elm
Researched on 2026-11-27. The example project under examples/ builds
with --optimize, passes elm-format, its tests and elm-review, all offline
in the Nix sandbox with Elm 0.19.2 from nixpkgs, and this repository's CI
reruns all of it on every commit. Claims marked researched come from
official docs and package metadata but were not exercised here.
Review after: 2027-02-27. Past that date, re-check the toolchain versions and tool behavior here against nixpkgs and the linked sources before relying on them, then update this date and the research date.
Establish the toolchain first
Read elm.json ("elm-version" and dependencies) and the project's Nix pin
before changing anything. elm --version must equal elm.json's
elm-version, and the test runner must use the same compiler.
- Use the Elm in the project's nixpkgs pin, with nixpkgs'
elm-format,elm-test-rsandelm-review. As of 2026-11-27 that is 0.19.2. Do not install the compiler from npm or a release download. - Elm 0.19.2 brought faster builds and no language changes, so 0.19.1
code, tutorials and packages still apply. Upgrading means changing
elm-version, the compiler and the test runner together, by advancing the nixpkgs pin. - Builds and checks run inside Nix with no network. Copy the example's
default.nix,checks.nixandnix/directory, and read toolchain and Nix before setting up or changing an Elm build, test runner, minifier or elm-review.
Verification loop
elm make src/Main.elm --output=/dev/nullwhile editing.elm make src/Main.elm --optimizefor release. It refuses to generate output if anyDebug.log,Debug.todoorDebug.toStringremains. Judge by the exit status and the output file: Elm prints "Success! Compiled N modules." before the DEBUG REMNANTS failure.elm-format --validate src tests review/src. Never hand-align code; elm-format has no options by design.elm-test-rs --offline --compiler "$(command -v elm)"andelm-review --offline --compiler "$(command -v elm)".nix flake check, withdefault.nixexposed as the package and as a check, andchecks.nixas a check. checks.nix runs steps 3 and 4 in the sandbox;./testruns the flake checks.
Elm code you write or change must pass elm-review before you report the
work done, along with the formatter and tests. Fix findings rather than
disabling rules; on the example, elm-review caught unused constructor
arguments, missing let annotations and unexposed types. If the project has
no review/ configuration, add one as
toolchain and Nix describes and
wire it into the checks. Running elm-review --template ... without a local
configuration does not work: the template targets Elm 0.19.1 and fails with
ELM VERSION MISMATCH.
elm-review --fix-all deletes code it thinks is unused. Its NoUnused
fixes remove exports, functions, type aliases and constructors that nothing
uses yet, and re-run until none remain, so code written ahead of its callers
(a module the next commit will use, a constructor a later port will create)
disappears, sometimes down to one constructor of a type. Apply fixes with
--rules NoPrematureLetComputation,Simplify,... naming only the rules you
mean, review the diff before keeping it, and commit first so the fixer cannot
destroy uncommitted work.
A successful compile proves types, not behavior. Test decoders against real
payloads, including missing, null and wrong-typed fields.
Model the domain before writing views
- Replace booleans, strings and clusters of
Maybefields with custom types.{ loading : Bool, error : Maybe String, data : Maybe a }allows impossible states;type Remote a = Loading | Failed Http.Error | Loaded adoes not. - Wrap identifiers and validated values in opaque types with smart
constructors (
type CardId = CardId String, exposing the type but not the constructor). Parse untrusted input once at the boundary into precise types. - Keep structured errors such as
Http.Errorin the model and render them inview, rather than flattening them to strings inupdate. - For grouping by a constructor that carries data, add a payload-free kind
type (
StatusKind) instead of placeholder values such asBlocked "". - Derive an "every value" list from an exhaustive
case(seeallKindsin Card.elm) so a new constructor cannot be silently left out of menus or columns. - Annotate every top-level definition and every
letbinding. Shadowing is a compile error: a parameter named like any top-level value (status,title,model) fails. - A message carries only data its handler uses:
Time.every 1000 (\_ -> Tick)rather thanTick Time.Posixwith the time ignored.
Read architecture for scaling an app, effects, interop, rendering performance and testing.
JSON decoding: the trap that compiles
Json.Decode.maybe and oneOf [ field ..., succeed default ] treat a field
that is present but malformed exactly like a missing one. A wrong-typed
assignee becomes Nothing, and one malformed nested item silently empties
a whole subtasks list. An unaided agent wrote both patterns in testing and
then described its own code as failing on bad input, which it does not. Fall
back only when the field is absent:
optional : String -> Decoder a -> Decoder (Maybe a)
optional name valueDecoder =
Decode.oneOf
[ Decode.field name Decode.value |> Decode.map (\_ -> True)
, Decode.succeed False
]
|> Decode.andThen
(\present ->
if present then
Decode.map Just (Decode.field name valueDecoder)
else
Decode.succeed Nothing
)DecodeField.elm adds the null-tolerant form,
and Tests.elm proves both the trap and the fix.
Recursive decoders need Decode.lazy; tagged unions decode with andThen on
the tag; report failures with Decode.errorToString. Read
JSON before writing or reviewing decoders or encoders.
Architecture in brief
- Choose the lightest program:
Browser.elementto embed in a page,Browser.documentto own the body,Browser.applicationfor URL routing. - Do not build nested "components" with their own
Model/Msg/updateby default. Use view functions that take data and message constructors; give a page or a genuinely stateful widget its own module when it earns it. - Organize modules around a central type. Split along types when a file passes about 500 lines (the fleet's limit) rather than into Model/Update/View files.
subscriptionsis a pure function of the model: returnSub.noneto stop.Cmd.batchruns commands in no guaranteed order.- Decode flags from
Json.Decode.Value. Prefer one tagged port pair over a port per JavaScript function. Ports are asynchronous, carry only JSON-compatible values, and are not allowed in published packages.
Compile errors agents commonly hit
| Mistake | Fix |
{ model.sub | x = 1 } (PROBLEM IN RECORD) | bind model.sub in a let, then update it |
a module named Task, List, Dict, ... (AMBIGUOUS IMPORT) | a domain name (Card) |
| importing an indirect dependency (MODULE NOT FOUND) | elm install it to make it direct |
| a parameter named like a top-level value (SHADOWING) | a distinct name (cardStatus) |
| a tuple of four or more | a record |
/ on Int, or // on Float | // for Int, toFloat n / 2 for Float |
Read mistakes for the full catalog with causes and
fixes: numeric types, comparable keys, recursion depth, DOM pitfalls,
interop and tooling.
Dependencies
Add packages with elm install author/package, including packages that are
already indirect dependencies but are now imported directly. Set up tests
with elm-test-rs init: in an application, elm install elm-explorations/test
wrongly lands in production dependencies. Review the elm.json diff instead
of piping yes into prompts, never hand-edit application dependency
versions, and keep elm-stuff/ out of version control. Regenerate
elm-srcs.nix with elm2nix convert whenever an elm.json changes, in the
application and in review/; evaluation fails until you do.
Worked example
examples/ is a small Browser.element board: decoded flags,
an opaque CardId, a Remote loading type, strict optional-field decoders, a
recursive decoder, an exhaustive kind list, a keyed list, a conditional
subscription and one tagged port. default.nix builds
it offline with nixpkgs' Elm and the official minifier settings,
checks.nix runs elm-format, the
tests and elm-review with the
standard rule set, and
nix/elm-home.nix supplies the packages offline.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

