So I have a simple data structure that has some ByteStrings. I want to serialize these into Dhall files. However, I apparently can't just automatically derive ToDhall, since there's no instance for ToDhall. How do I write that?
data WordBounds = WordBounds { zipFile :: Prelude.FilePath
, start :: BS.ByteString
, end :: BS.ByteString
} deriving (Show, Generic, ToDhall)
I've tried instance ToDhall BS.ByteString and I think I'm getting closer, but I still don't quite understand what the syntax of instance is trying to do, and/or how to get it to work with Dhall.
From the documentation, it looks like you could do something like this:
This uses the two existing instances for
ToDhall:...so the
injectWithon the RHS of the equation is for[Word8], not a recursive call to the one forByteString. It also usesto convert an
Encoder [Word8]to anEncoder ByteString.That said, this will be an orphan instance. Most of the community would recommend that you do not do that. Alternatives include creating a
newtype, as inand writing instances for that instead, or simply writing
and then using that in a hand-written
instance ToDhall WordBounds.