yesodweb / yesodweb/persistent
Automatic (TH) PathPiece generation is poorly documented, and confusing
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
The documentation for mkPersist says
Create data types and appropriate
PersistEntityinstances for the givenEntityDefs. Works well with the persist quasi-quoter.
I'm struggling to understand why it also creates PathPiece instances. In particular, I have hit a confusing issue where, with more than two tables being defined, using an enum type (whose instances where generated via derivePersistField) in the one table causes the compiler to complain that the data type does not have the appropriate path-pieces instances, but enums in another table do not cause the same error.
The source code for the module reads
-- | declare the key type and associated instances
-- @'PathPiece'@, @'ToHttpApiData'@ and @'FromHttpApiData'@ instances are only generated for a Key with one field
mkKeyTypeDec :: MkPersistSettings → EntityDef → Q (Dec, [Dec])
What does this even mean?? Note that my project does not use Yesod (yet), so I'm finding it difficult to justify creating PathPiece and *HttpApiData instances just to satisfy the compiler when there aren't any actual paths in the code base, or any other hint of HTTP.
On a possibly-related note, declaring but right now my guesses are worthless.DeriveGeneric and DeriveAnyClass as default extensions in my project causes mkPersist to blow up and start complaining about missing Generic instances. That is, I guess this might be a weird extensions issue,
If necessary, I can try and create a minimal example producing the issue. But I'm hoping this rings a bell and has been encountered by someone else before.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the mkPersist documentation and the mkKeyTypeDec entry point, including its PathPiece, ToHttpApiData, and FromHttpApiData comment. Reproduce the reported enum case with a minimal example if needed; done means the generated instances and their conditions are clearly explained in the documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100