Add decoding utils#984
Open
alexfmpe wants to merge 4 commits into
Open
Conversation
alexfmpe
commented
Sep 11, 2022
| => (err -> (b -> parse a) -> (b -> parse a)) | ||
| -> Encoder check parse a b | ||
| -> Encoder check parse a b | ||
| retryEncoder retry = unsafeWrapDecoding $ \p b -> catchError (p b) $ \e -> retry e p b |
Contributor
Author
There was a problem hiding this comment.
Note this only satisfies unsafeWrapDecoding's law if we can trust MonadError to preserve success (well, non-failure). Which I wager we should, but the documentation has no laws whatsoever.
Currently being discussed in the mailing list: https://mail.haskell.org/pipermail/libraries/2022-September/031621.html
6 tasks
alexfmpe
commented
Sep 26, 2022
| -- Thus, to produce a law-abiding encoder, we need only preserve parse success. | ||
| unsafeWrapDecoding | ||
| :: Functor check | ||
| => ((b -> parse a) -> (b -> parse' a)) -- ^ Required law for @wrap@ argument: @forall a b. p b = pure a => wrap p b = pure a@ |
Contributor
Author
There was a problem hiding this comment.
It seems hoistParse also implicitly relies on a simplified version of this law, having wrap = (f,). For instance
hoistParse $ const $ throwError "bla"will break roundtrips when we're encoding from inhabited types.
Should it be renamed to have an unsafe prefix?
ryantrinkle
reviewed
Oct 5, 2024
|
|
||
| -- | Completely override the decoding function. | ||
| -- Since the only 'Encoder' law is round-tripping, values that fail to parse are unconstrained. | ||
| -- Thus, to produce a law-abiding encoder, we need only preserve parse success. |
Member
There was a problem hiding this comment.
"preserve the value of successful parses", not just their successfulness
ryantrinkle
approved these changes
Oct 5, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original motivation was supporting some kind of canonicalization to allow each route to be decoded to from several urls. A lot of semantic agony later, this is what I ended up with.
I have:
developbranchhlint .(lint found code you did not write can be left alone)$(nix-build -A selftest --no-out-link)nix-build release.nix -A build.x86_64-linux --no-out-link(orx86_64-darwinon macOS)