Gabriella439 / Gabriella439/optparse-generic
Sum type parsing
- Dominant language
- Haskell
- Stars
- 215
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I wanted to use a sum type in my command line parsing, and I came up with this:
```haskell
data FrontendLanguage = Typescript | Swift deriving (Eq, Show, Read, Generic)
instance ParseField FrontendLanguage
instance ParseRecord FrontendLanguage
instance ParseFields FrontendLanguage
data Tasks
= GenerateRoutes
{ language :: FrontendLanguage "Options are: Typescript, Swift"
, frontendRepo :: FilePath "Path to the root of the frontend repo"
}
deriving (Generic, Show)
instance ParseRecord Tasks
```
It works fine in the success case, though there isn't a specific error message if you provide an invalid sum type, just the generic help text.
Is this the best way to do this? I couldn't find anything in the documentation about this (could have missed it, though). If it is the best way, I'll submit a PR to document this use-case in the Haddocks if you'd like.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the existing Haddocks for ParseField, ParseRecord, and ParseFields, then check how sum-type parsing and invalid values are currently described. Confirm whether this pattern is supported and how failures are reported; done means documenting the working usage and its error behavior, or recording that the approach needs a separate change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- cli
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100