Difference between revisions of "Functor"

From HaskellWiki
Jump to navigation Jump to search
m (Adding Monad category)
m (fix broken link)
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Standard class|Functor|module=Control.Monad|module-doc=Control-Monad|package=base}}
+
{{Standard class|Functor|module=Data.Functor|module-doc=Data-Functor|package=base}}
 
The '''Functor''' class is defined like this:
 
The '''Functor''' class is defined like this:
   
 
class Functor f where
 
class Functor f where
 
fmap :: (a -> b) -> f a -> f b
 
fmap :: (a -> b) -> f a -> f b
  +
  +
It is available in the Prelude, but defined in Data.Functor.
   
 
All instances of Functor should obey:
 
All instances of Functor should obey:
   
fmap id = id
+
fmap id = id
 
fmap (p . q) = (fmap p) . (fmap q)
 
fmap (p . q) = (fmap p) . (fmap q)
   
  +
[[Category:Standard classes]]
 
  +
== More reading ==
[[Category:Monad]]
 
  +
  +
* [http://www.haskellforall.com/2012/09/the-functor-design-pattern.html The functor design pattern]
  +
  +
  +
 
[[Category:Functor|*]]

Revision as of 21:14, 13 October 2014

Functor class (base)
import Data.Functor

The Functor class is defined like this:

class Functor f where
  fmap :: (a -> b) -> f a -> f b

It is available in the Prelude, but defined in Data.Functor.

All instances of Functor should obey:

fmap id      = id
fmap (p . q) = (fmap p) . (fmap q)


More reading