agentleFS
pmarreckpmarreck/llm_skills/writing-elm/SKILL.md

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.

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
  1. Very specific:

    Read elm.json ("elm-version" and dependencies) and the project's Nix pin before changing anything.

    line 20
  2. Very specific:

    Keep structured errors such as Http.Error in the model and render them in view, rather than flattening them to strings in update.

    line 81
  3. Distinctive:

    Read architecture for scaling an app, effects, interop, rendering performance and testing.

    line 94
  4. Very specific:

    Do not build nested "components" with their own Model/Msg/update by default.

    line 133
  5. Very specific:

    Read mistakes for the full catalog with causes and fixes: numeric types, comparable keys, recursion depth, DOM pitfalls, interop and …

    line 156
  6. Very specific:

    Add packages with elm install author/package, including packages that are already indirect dependencies but are now imported directly.

    line 162

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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-rs and elm-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.nix and nix/ directory, and read toolchain and Nix before setting up or changing an Elm build, test runner, minifier or elm-review.

Verification loop

  1. elm make src/Main.elm --output=/dev/null while editing.
  2. elm make src/Main.elm --optimize for release. It refuses to generate output if any Debug.log, Debug.todo or Debug.toString remains. Judge by the exit status and the output file: Elm prints "Success! Compiled N modules." before the DEBUG REMNANTS failure.
  3. elm-format --validate src tests review/src. Never hand-align code; elm-format has no options by design.
  4. elm-test-rs --offline --compiler "$(command -v elm)" and elm-review --offline --compiler "$(command -v elm)".
  5. nix flake check, with default.nix exposed as the package and as a check, and checks.nix as a check. checks.nix runs steps 3 and 4 in the sandbox; ./test runs 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 Maybe fields with custom types. { loading : Bool, error : Maybe String, data : Maybe a } allows impossible states; type Remote a = Loading | Failed Http.Error | Loaded a does 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.Error in the model and render them in view, rather than flattening them to strings in update.
  • For grouping by a constructor that carries data, add a payload-free kind type (StatusKind) instead of placeholder values such as Blocked "".
  • Derive an "every value" list from an exhaustive case (see allKinds in Card.elm) so a new constructor cannot be silently left out of menus or columns.
  • Annotate every top-level definition and every let binding. 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 than Tick Time.Posix with 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.element to embed in a page, Browser.document to own the body, Browser.application for URL routing.
  • Do not build nested "components" with their own Model/Msg/update by 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.
  • subscriptions is a pure function of the model: return Sub.none to stop. Cmd.batch runs 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

MistakeFix
{ 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 morea 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.