Cookbook¶
Practical patterns and recipes for using Typist in real projects. Each page addresses a specific problem area with complete, working code examples.
These recipes assume familiarity with the basics covered in the Guide. All examples use use v5.40; use Typist; and place type definitions in BEGIN blocks.
Recipes¶
| Page | Description |
|---|---|
| Domain Modeling | Opaque newtypes, rich structs, state machines with ADTs, and compositional domain types |
| Error Handling | Result and Option types, effect-based error handling, combining results with effects |
| Multi-File Projects | Shared type modules, cross-file resolution, namespace model, ImportHint diagnostics |
| Gradual Migration | Step-by-step migration of existing Perl code, before/after examples, CI integration |
Conventions Used¶
- All type definitions appear in
BEGINblocks (required for compile-time visibility, including opt-in CHECK analysis). - String syntax is used for type expressions:
'Int', not bareInt. +{}is used for hashref literals to avoid block/hashref ambiguity.- No comma after blocks in
handle/map/grep(prototype rule).