-
Notifications
You must be signed in to change notification settings - Fork 219
updated documentation strings to include empty tag in a union #2625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -943,6 +943,7 @@ encodeFieldWith name encodeType = RecordEncoder $ Dhall.Map.singleton name encod | |||||||||||||||||
data Status = Queued Natural | ||||||||||||||||||
| Result Text | ||||||||||||||||||
| Errored Text | ||||||||||||||||||
| Unreachable () | ||||||||||||||||||
:} | ||||||||||||||||||
|
||||||||||||||||||
And assume that we have the following Dhall union that we would like to | ||||||||||||||||||
|
@@ -951,6 +952,7 @@ data Status = Queued Natural | |||||||||||||||||
> < Result : Text | ||||||||||||||||||
> | Queued : Natural | ||||||||||||||||||
> | Errored : Text | ||||||||||||||||||
> | Unreachable | ||||||||||||||||||
> >.Result "Finish successfully" | ||||||||||||||||||
|
||||||||||||||||||
Our encoder has type 'Encoder' @Status@, but we can't build that out of any | ||||||||||||||||||
|
@@ -963,11 +965,13 @@ injectStatus = adapt >$< unionEncoder | |||||||||||||||||
( encodeConstructorWith "Queued" inject | ||||||||||||||||||
>|< encodeConstructorWith "Result" inject | ||||||||||||||||||
>|< encodeConstructorWith "Errored" inject | ||||||||||||||||||
>|< encodeConstructorWith "Unreachable" inject | ||||||||||||||||||
) | ||||||||||||||||||
where | ||||||||||||||||||
adapt (Queued n) = Left n | ||||||||||||||||||
adapt (Result t) = Right (Left t) | ||||||||||||||||||
adapt (Errored e) = Right (Right e) | ||||||||||||||||||
adapt (Queued n) = Just (Left n) | ||||||||||||||||||
adapt (Result t) = Just (Right (Left t)) | ||||||||||||||||||
adapt (Errored e) = Just (Right (Right e)) | ||||||||||||||||||
adapt Unreachable = Nothing | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
:} | ||||||||||||||||||
|
||||||||||||||||||
Or, since we are simply using the `ToDhall` instance to inject each branch, we could write | ||||||||||||||||||
|
@@ -978,11 +982,13 @@ injectStatus = adapt >$< unionEncoder | |||||||||||||||||
( encodeConstructor "Queued" | ||||||||||||||||||
>|< encodeConstructor "Result" | ||||||||||||||||||
>|< encodeConstructor "Errored" | ||||||||||||||||||
>|< encodeConstructor "Unreachable" | ||||||||||||||||||
) | ||||||||||||||||||
where | ||||||||||||||||||
adapt (Queued n) = Left n | ||||||||||||||||||
adapt (Result t) = Right (Left t) | ||||||||||||||||||
adapt (Errored e) = Right (Right e) | ||||||||||||||||||
adapt (Queued n) = Just (Left n) | ||||||||||||||||||
adapt (Result t) = Just (Right (Left t)) | ||||||||||||||||||
adapt (Errored e) = Just (Right (Right e)) | ||||||||||||||||||
adapt Unreachable = Nothing | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I am getting a bit lost. The documentation on Hackage --- I think it is different from the docstring in the source file which I have been editing. Is this a newer version? What does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's been a while since the last release to Hackage, which is the reason for the difference. However, I'm working on cutting a new release soon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stackage would also be great. It would enable Hoogle... |
||||||||||||||||||
:} | ||||||||||||||||||
|
||||||||||||||||||
-} | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how I had it:
data DateFinished = Current () | Done DATE.Day | Dropped () deriving (Generic, Show, Eq)
and then:
But if I do as you suggested, i.e.
data DateFinished = Current | Done DATE.Day | Dropped deriving (Generic, Show, Eq)
--- then it does not compileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change that to:
… then it should compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I got it ! Cute (although smells of witchcraft...). Then, maybe, instead of my suggested patch, would you rather write something pedagogical, in that docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just requested the pull for the correcting patch, as you suggested.