preferences-haskell-development
Haskell development conventions covering type classes, monadic composition, and GHC extensions. Load when working with .hs files or Haskell projects.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Haskell Development
Architectural patterns alignment
See @~/.claude/skills/preferences-architectural-patterns/SKILL.md for overarching principles.
Haskell embodies the theoretical ideal of functional programming with native support for monad transformers, lawful abstractions, and referential transparency. It serves as the reference model that other languages approximate with their respective libraries (Effect-TS, ZIO, etc.).
Core patterns and libraries
-
Effect composition: Use monad transformers from
transformersandmtlfor composing effects -
Error handling:
EitherandMaybefor composable error handling, no exceptions -
State management:
StateTfor explicit state threading through computations -
Reader pattern:
ReaderTfor dependency injection and configuration - IO isolation: Isolate IO effects to boundaries, keep pure functions pure
- Type-level programming: Leverage type classes, GADTs, and type families for compile-time guarantees
Monad transformer stacks
- Structure applications as monad transformer stacks (e.g.,
ReaderT Config (StateT AppState (ExceptT Error IO))) - Ensure all monad instances are lawful (identity, associativity for bind)
- Use
liftandliftIOto traverse effect transformer stacks - Apply newtype wrappers for domain-specific effect stacks
Type safety and purity
- Leverage Haskell's type system to make illegal states unrepresentable
- Use
newtypefor domain-specific types to prevent mixing incompatible values - Encode effects explicitly in type signatures (IO, State, Reader, etc.)
- Prefer total functions; use
Maybe/Eitherinstead of partial functions - Use smart constructors to enforce invariants at construction time
Recommended libraries
-
Monad transformers:
transformers,mtl -
Effect systems:
polysemy,eff,freer-simplefor more flexible effect composition -
Parsing:
megaparsec,attoparsecfor parser combinators -
Error handling:
either,validation,errorsfor enhanced error composition -
Testing:
QuickCheckfor property-based testing,hspecfor BDD-style tests -
Lenses:
lensoropticsfor functional record updates
Code quality and tooling
- Use
hlintfor linting and style suggestions - Use
ormolu,fourmolu, orstylish-haskellfor consistent formatting - Enable
-Walland-Wcompatfor comprehensive warnings - Use
ghcidfor fast feedback during development - Run
stack testorcabal testbefore committing
Project structure
- Use Stack or Cabal for package management
- Organize code into modules with clear public APIs
- Separate pure business logic from IO-heavy code
- Use
src/for library code,app/for executables,test/for tests - Document public functions with Haddock comments
Best practices
- Write point-free style judiciously (when it improves clarity)
- Use pattern matching exhaustively
- Leverage lazy evaluation but be aware of space leaks
- Profile with
-profand+RTSflags before optimizing - Use strict fields in data types when appropriate (
!bang patterns) - Consider strictness annotations for performance-critical code
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!