Building a List of FileData Values
Now that we have created a way to hold information about a specific file, and to serialize it, we should turn our eyes toward representing a collection of files. The minimal implementation here is pretty easy thanks to the work that we’ve done with supporting encoding lists. We’ll make a newtype wrapper around a list of values, and while we’re at it, we’ll go ahead and give it an Encode instance. We’re manually specifying the instance here because if we use newtype deriving we’ll once again run into an overlapping instances problem.
| instance Encode a => Encode (FilePack a) where |
| encode (FilePack a) = encode a |
We can use this to create files pretty easily:
| λ filePack = FilePack [ FileData ... |
Get Effective Haskell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.