title: Making Data.Map a functor in Haskell
body: <p>I'm studying the basics of Haskell from <a href="http://learnyouahaskell.com/" rel="noreferrer">Learn You a Haskell for Great Good!</a></p>
  
  <p>There is an exercise in the book where you need to make Data.Map into a Functor.</p>
  
  <p>I'm trying to make my own functor typeclass and make Data.Map into an instance of it.</p>
  
  <p>So here's what I tried:</p>
  
  <pre><code>import Data.Map as DataMap
  import Data.List as DataList
  
      class MyFunctor f where
          myfmap :: (a -&gt; b) -&gt; f a -&gt; f b
  
      instance MyFunctor (Ord k) =&gt; (DataMap.Map k) where
          myfmap f x = DataMap.fromList $ DataList.map (\(p,q) -&gt;(p,f q)) $ DataMap.toList x
  </code></pre>
  
  <p>When I try to compile this, GHCI gives me this error:</p>
  
  <pre><code>`myfmap' is not a (visible) method of class `Map'
  </code></pre>
  
  <p>I tried looking around other SO answers, blogs, mailing list threads etc without much luck.</p>
  
  <p>The only thing I found was the description of the error message in the <a href="http://www.haskell.org/haskellwiki/GHC/Error_messages#.22.60foo.27_is_not_a_.28visible.29_method_of_class_.60Bar.27.22" rel="noreferrer">Haskell Wiki</a> which says that GHCI throws this error when one tries to instantiate a class, but did not import the functions one tries to implement.</p>
  
  <p>I have imported Data.Map and Data.List so I don't think that's the real cause. </p>
  
  <p>What am I doing wrong?</p>