Skip to content

Commit

Permalink
Merge pull request #219 from pcapriotti/topic/improve-ReadM-doc
Browse files Browse the repository at this point in the history
Update Readme's description of parseFluxCapacitor to use eitherReader
  • Loading branch information
HuwCampbell committed Aug 9, 2016
2 parents 8aa2161 + 9b75391 commit bf71086
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,23 @@ output type. There's usually no need to add type annotations, however, because
the type will be normally inferred from the context in which the parser is
used.

You can also create a custom reader that doesn't use the `Read` typeclass, and
use it to parse option arguments. A custom reader is a value in the `ReadM`
monad.
One can also create a custom reader that doesn't use the `Read` typeclass, and
use it to parse option arguments. A custom reader is a value in the `ReadM`
monad. We provide `eitherReader :: (String -> Either String a) -> ReadM a`
to help create these values, where a `Left` will be hold the error message
for a failure.

```haskell
data FluxCapacitor = ...

parseFluxCapacitor :: Monad m => String -> m FluxCapacitor
parseFluxCapacitor :: ReadM FluxCapacitor
parseFluxCapacitor = eitherReader $ \s -> ...

option (str >>= parseFluxCapacitor)
( long "flux-capacitor" )
option parseFluxCapacitor ( long "flux-capacitor" )
```

Use `readerAbort` or `readerError` within the `ReadM` monad to exit with an
One can also use `ReadM` directly, using `str` to obtain the command line string,
and `readerAbort` or `readerError` within the `ReadM` monad to exit with an
error message.

### Flags
Expand Down

0 comments on commit bf71086

Please sign in to comment.