A Functor is a Haskell type class for parameterized types whose contained value can be transformed with fmap. Its core type, fmap :: Functor f => (a -> b) -> f a -> f b, applies a function while retaining the surrounding structure. section 8.2.3
Lists, Maybe, Either, tuples, IO actions, and parsers can all preserve their own context while their inner result changes. Int cannot be a Functor because it is a concrete type rather than a type accepting a parameter. section 8.2.3 section 8.4
Map a successful CSV result
CSV parsing returns Either String Csv. Using <$> maps unsafeMkCsv over a successful result from parseColumns, while an error remains a Left. The infix operator <$> is fmap. section 8.2.2 section 8.5
Map inside IO
getArgs returns IO [String]. Writing map T.pack <$> getArgs transforms the argument strings to Text without first extracting the list from IO; the result remains IO [Text]. section 8.4
Listing 12.5 A functor instance for parsers
instance Functor Parser where fmap f p = Parser $ \t -> fmap (fmap f) (runParser p t) #1
A Parser Functor maps a conversion over the successful parsed value nested inside Either and a result tuple, preserving input remainder and parse failures. section 12.1.2
Functor instances also make parsers more precise. A parser for the text "P1" can become a Parser MagicNumber by mapping const P1; <$ is shorthand when every successful result should become one constant value. section 12.1.2
For a custom RandomIO generator, a Functor instance would provide the equivalent of map: transform generated values while leaving generation in the RandomIO context. section 9.1.6





