From 51de0d65710152d3a83c037d1de2768e8c2f4a3e Mon Sep 17 00:00:00 2001 From: Andrei Mikhailov Date: Sat, 4 Jan 2025 13:54:34 -0300 Subject: [PATCH] updated documentation strings to include the case of empty tag in a union --- dhall/src/Dhall/Marshal/Encode.hs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dhall/src/Dhall/Marshal/Encode.hs b/dhall/src/Dhall/Marshal/Encode.hs index 4ba9e0055..5ae18cf4f 100644 --- a/dhall/src/Dhall/Marshal/Encode.hs +++ b/dhall/src/Dhall/Marshal/Encode.hs @@ -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 :} 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 :} -}