practical-haskell
Skill1 starsChanged 8 months agoMITView on GitHub
Guides efficient Haskell aligned with GHC practice -- laziness and strictness, purity, fusion, newtypes, pragmas, Core reading, and space-leak avoidance. Use when writing or reviewing Haskell, optimizing or profiling, debugging strictness or memory, or when the user mentions GHC, thunks, foldl vs foldl', list fusion, SPECIALIZE, or UNPACK.
In this repository33 other files it gives its agents.
- argocdSkill
- c-cpp-compilersSkill
- coding-guidelinesSkill
- devops-iac-engineerSkill
- dag-flowdSkill
- flowd-rules-authorSkill
- frontend-designSkill
- ghSkill
- grafana-dashboardsSkill
- helmSkill
- kustomizeSkill
- legalizerSkill
- lua-projectsSkill
- markdown-documentationSkill
- mermaid-diagramsSkill
- meta-cognition-parallelSkill
- podmasterSkill
- rcaSkill
- researcherSkill
- security-auditSkill
- solidity-securitySkill
- svg-genSkill
- tdd-red-green-refactorSkill
- tmux-masterySkill
- tokenomics-designSkill
- ultimate-dbSkill
- ultimate-nixosSkill
- ultimate-rustSkill
- ultimate-web3Skill
- web3-frontendSkill
- web3-testingSkill
- web3-whitepaperSkill
- ziglangSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Use this skill when the task is Haskell code quality, performance, or reasoning about evaluation.
- Very specific: line 15
Know what GHC emits: when performance matters, treat Core (-ddump-simpl) as ground truth after optimization.
- Very specific: line 20
Prefer foldl' from Data.List (or strict folds from the right library) for numeric accumulation over plain foldl on strict values.
- Distinctive: line 22
Write small composable functions.
- Very specific: line 23
Use fusion-friendly pipelines (map, filter, foldr-based idioms) where appropriate.
- Distinctive: line 30
Treat laziness as universally good or bad.
- Very specific: line 80
Use newtype for distinct types with identical representation.
- Very specific: line 87
Use {-# SPECIALIZE #-} for concrete instantiations.
- Very specific: line 88
Use {-# INLINABLE #-} on small polymorphic helpers so call sites can specialize.
- Distinctive: line 90
Verify with Core, not assumptions.
- Distinctive: line 97
Look for fusion: one tight recursive loop vs multiple passes.
- Distinctive: line 98
Check whether dictionary calls remain in hot loops.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Practical Haskell (GHC)
Use this skill when the task is Haskell code quality, performance, or reasoning about evaluation. Assume GHC with optimizations (-O / -O2) unless the user says otherwise.
Core ideas
- Purity lets the compiler rewrite code safely; prefer explicit effects in
IOor appropriate abstraction. - Lazy by default: values are evaluated when needed. That enables composition but can hide space leaks.
- Types catch many bugs early; use them to encode intent (including
newtypefor domain distinctions). - Know what GHC emits: when performance matters, treat Core (
-ddump-simpl) as ground truth after optimization.
Always
- Be explicit about strict vs lazy data and bindings when modeling accumulators, parsers, or long-lived state.
- Prefer
foldl'fromData.List(or strict folds from the right library) for numeric accumulation over plainfoldlon strict values. - Profile (
profiling, eventlog,ghc-debug, etc.) before micro-optimizing. - Write small composable functions; rely on inlining and specialization rather than giant monoliths.
- Use fusion-friendly pipelines (
map,filter,foldr-based idioms) where appropriate; validate hot paths in Core if allocation matters.
Never
- Accidentally build large chains of thunks (classic
foldl (+) 0on large strict sums). - Ignore space leaks from unevaluated structure holding onto memory.
- Micro-optimize without evidence from profiling or Core.
- Treat laziness as universally good or bad; decide per use case.
Prefer
- Strict fields (
!) on accumulator-like constructor fields;UNPACKfor small unboxed numeric fields when profiling supports it. - Newtypes for zero-runtime-cost distinctions vs
datawith a single field. INLINE/INLINABLE/SPECIALIZEon hot polymorphic glue when dictionaries or lack of specialization shows up in Core.- Worker/wrapper style: a strict internal worker and a small external API.
- Monomorphic hot loops when polymorphism still costs after specialization attempts.
Laziness and strictness
import Data.List (foldl')
-- Infinite lists are fine when consumption is bounded.
naturals :: [Integer]
naturals = [1..]
firstTen :: [Integer]
firstTen = take 10 naturals
-- foldl on strict arithmetic often leaks thunks; foldl' forces as it goes.
badSum :: [Int] -> Int
badSum = foldl (+) 0
goodSum :: [Int] -> Int
goodSum = foldl' (+) 0Bang patterns ({-# LANGUAGE BangPatterns #-}) force evaluation of a binding; use at strategic places (accumulators, fields that must not retain thunks).
Strict fields on data constructors evaluate to WHNF when the constructor is entered; combine with profiling to avoid over-forcing.
Fusion and lists
List pipelines like sum . map f . filter p often fuse under -O2 into a single loop. If allocation persists, inspect Core. Avoid forcing materialization unnecessarily (e.g. redundant length or indexing on huge intermediates in hot code).
GHC applies rewrite rules internally; custom {-# RULES #-} is advanced and must be validated (correctness and phase interactions).
Newtypes
newtype UserId = UserId Int
deriving (Eq, Ord, Show)
newtype Email = Email String
deriving (Eq, Show)Use newtype for distinct types with identical representation. GeneralizedNewtypeDeriving can derive classes when appropriate and policy allows.
Specialization and inlining
Polymorphic hot code may pass type-class dictionaries. Mitigations:
- Give a monomorphic variant for the hot path.
- Use
{-# SPECIALIZE #-}for concrete instantiations. - Use
{-# INLINABLE #-}on small polymorphic helpers so call sites can specialize.
Verify with Core, not assumptions.
Reading Core (quick guide)
Compile with something like ghc -O2 -ddump-simpl -dsuppress-all -dno-suppress-type-signatures YourModule.hs (flags vary by need).
caseusually forces evaluation; extraletbindings can mean allocation.- Look for fusion: one tight recursive loop vs multiple passes.
- Check whether dictionary calls remain in hot loops.
Mental checklist
- When does each subexpression get forced?
- Where might thunks retain memory (closures, lazy fields,
foldl-style accumulation)? - Will this pipeline fuse or allocate intermediates?
- What does simplified Core show for the hot path?
- Is the hot code monomorphic and specialized?
Signature moves (when profiling says so)
- Strict accumulators:
foldl', bang patterns, strict fields. UNPACKsmall strict numeric fields to reduce indirection.INLINE/INLINABLE/SPECIALIZEto recover specialization.- Fusion-friendly combinators; avoid accidental intermediate lists in inner loops.
- Worker/wrapper refactor for clearer strict internals.
- Re-check Core after each change.
Additional resources
For extended examples and GHC flag recipes, see reference.md.
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.

