ClassyPrelude has two display functions, namely:
map works with any Functor . However, things like Text are not functors, since they are not universal containers. That is, they cannot contain any type, unlike a list. As seen from the following code:
module Main where import Prelude () import ClassyPrelude import qualified Data.Text as T import Data.Char as C main = do let l = [1,2,3] :: [Int] let t = (T.pack "Hello") let m = Just 5 print $ map (*2) l print $ map (*2) m print $ omap C.toUpper t return ()
Note that you must use omap to work with Text . Since map requires the type to be Functor , map f text fails. The thing is, I found it trivially easy to override map to work for both calls. Here is the code:
{-
All that is required is to add instances to CanMap for any monomorphic containers. ClassyPrelude already does this anyway using the "omap" in the Data.MonoTraversable module. I suspect, however, that there is a good reason why I cannot understand why there should be two separate map functions for these alternative situations, but I wonder what it is.
source share