Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 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 (Errored e) = Right (Right (Left e))
adapt Unreachable = Right (Right (Right ()))
:}

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 (Errored e) = Right (Right (Left e))
adapt Unreachable = Right (Right (Right ()))
:}

-}
Expand Down