Skip to Content
Effective Haskell
book

Effective Haskell

by Rebecca Skinner
July 2023
Intermediate to advanced
670 pages
17h 13m
English
Pragmatic Bookshelf
Content preview from Effective Haskell

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Grokking Functional Programming

Grokking Functional Programming

Michal Plachta
Grokking Algorithms

Grokking Algorithms

Aditya Bhargava
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols

Publisher Resources

ISBN: 9798888650400Errata Page