Commit ce47a9c1 authored by Tobias Pflug's avatar Tobias Pflug Committed by Ben Gamari
Browse files

base: improve Functor documentation

- Rewrite module documentation
- Rewrite class documentation
parent 396aac4c
......@@ -11,8 +11,31 @@
-- Stability : provisional
-- Portability : portable
--
-- Functors: uniform action over a parameterized type, generalizing the
-- 'Data.List.map' function on lists.
--
-- A type @f@ is a Functor if it provides a function @fmap@ which, given any types @a@ and @b@,
-- lets you apply any function of type @(a -> b)@ to turn an @f a@ into an @f b@, preserving the
-- structure of @f@.
--
-- ==== __Examples__
--
-- >>> fmap show (Just 1) -- (a -> b) -> f a -> f b
-- Just "1" -- (Int -> String) -> Maybe Int -> Maybe String
--
-- >>> fmap show Nothing -- (a -> b) -> f a -> f b
-- Nothing -- (Int -> String) -> Maybe Int -> Maybe String
--
-- >>> fmap show [1,2,3] -- (a -> b) -> f a -> f b
-- ["1", "2", "3"] -- (Int -> String) -> [Int] -> [String]
--
-- >>> fmap show [] -- (a -> b) -> f a -> f b
-- [] -- (Int -> String) -> [Int] -> [String]
--
-- The 'fmap' function is also available as the infix operator '<$>':
--
-- >>> fmap show (Just 1) -- (Int -> String) -> Maybe Int -> Maybe String
-- Just "1"
-- >>> show <$> (Just 1) -- (Int -> String) -> Maybe Int -> Maybe String
-- Just "1"
module Data.Functor
(
......
......@@ -444,14 +444,12 @@ instance Semigroup a => Semigroup (IO a) where
instance Monoid a => Monoid (IO a) where
mempty = pure mempty
{- | The 'Functor' class is used for types that can be mapped over.
Instances of 'Functor' should satisfy the following laws:
{- | A type @f@ is a Functor if it provides a function @fmap@ which, given any types @a@ and @b@
lets you apply any function from @(a -> b)@ to turn an @f a@ into an @f b@, preserving the
structure of @f@. Furthermore @f@ needs to adhere to the following laws:
> fmap id == id
> fmap (f . g) == fmap f . fmap g
The instances of 'Functor' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'
satisfy these laws.
> fmap id == id
> fmap (f . g) == fmap f . fmap g
-}
class Functor f where
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment