July 2023
Intermediate to advanced
670 pages
17h 13m
English
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 ... |