category-theory-presentation/categories/30_How/100_Functors/030_Haskell_Functors_Example_List.html
2013-02-28 16:49:12 +01:00

9 lines
303 B
HTML

<h2>Haskell Functors Example: List</h2>
<pre class="haskell"><code>instance Functor ([]) where
fmap :: (a -> b) -> [a] -> [b]
fmap = map</pre></code>
<pre class="haskell"><code>fmap (+1) [1,2,3] == [2,3,4]
fmap (+1) [] == []
fmap head [[1,2,3],[4,5,6]] == [1,4]</code></pre>