Skip to content

Commit

Permalink
updated documentation strings to include the case of empty tag in a u…
Browse files Browse the repository at this point in the history
…nion
  • Loading branch information
Andrei Mikhailov committed Jan 4, 2025
1 parent ba62f0d commit 51de0d6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions dhall/src/Dhall/Marshal/Encode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
:}
Or, since we are simply using the `ToDhall` instance to inject each branch, we could write
Expand All @@ -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
:}
-}
Expand Down

0 comments on commit 51de0d6

Please sign in to comment.