<br><br><div class="gmail_quote">On Fri, Dec 17, 2010 at 11:04 AM, michael rice <span dir="ltr">&lt;<a href="mailto:nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top"><span style="font-family: courier,monaco,monospace,sans-serif;">I don&#39;t understand this error message. Haskell appears not to understand that 1 is a Num.<br>
<br>Prelude&gt; :t 1<br>1 :: (Num t) =&gt; t<br>Prelude&gt; :t [1,2,3,4,5]<br>[1,2,3,4,5] :: (Num t) =&gt; [t]<br>Prelude&gt; <br><br>Michael<br><br>===================<br><br>f :: [Int] -&gt; IO [Int]</span><br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">f lst = do return lst</span><br style="font-family: courier,monaco,monospace,sans-serif;"><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">main = do let lst = f [1,2,3,4,5]</span><br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">          fmap (+1) lst</span><br style="font-family: courier,monaco,monospace,sans-serif;"><br>===============================<br><br>Prelude&gt; :l test<br>
[1 of 1] Compiling Main             ( test.hs, interpreted )<br><br>test.hs:5:17:<br>    No instance for (Num [Int])<br>      arising from the literal `1&#39; at test.hs:5:17<br>    Possible fix: add an instance declaration for (Num [Int])<br>
    In the second argument of `(+)&#39;, namely `1&#39;<br>    In the first argument of `fmap&#39;, namely `(+ 1)&#39;<br>    In the expression: fmap (+ 1) lst<br>Failed, modules loaded: none.<br>Prelude&gt; <br></td></tr>
</tbody></table><br>

      <br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>Excuse any inaccuracies, I&#39;m somewhat new at Haskell myself, but what it
 looks like is happening is that at the point in main where you&#39;ve bound
 &quot;lst&quot;, it will have type of &quot;IO [Int]&quot;.  The signature for fmap is:<br>
<br>fmap :: (Functor f) =&gt; (a -&gt; b) -&gt; f a -&gt; f b<br clear="all"><br>if you call fmap (+1) the next argument that fmap &quot;expects&quot; is something that is &quot;in&quot; just one functor, for example, this<br>

<br><span style="font-family: courier,monaco,monospace,sans-serif;">fmap (+1) </span><span style="font-family: courier,monaco,monospace,sans-serif;">[1,2,3,4,5]</span><br><br>works fine, but, something that is &quot;IO [Int]&quot; won&#39;t.  You can compose two &#39;fmap&#39;s to solve this:<br>

<br>:t (fmap.fmap)<br>(fmap.fmap)<br>  :: (Functor f, Functor f1) =&gt; (a -&gt; b) -&gt; f (f1 a) -&gt; f (f1 b)<br><br>which means that &#39;main&#39; looks like:<div class="im"><br><br>main = do let lst = f [1, 2, 3, 4, 5]<br>
</div>          (fmap.fmap) (+1) lst<br><font color="#888888">
</font><br clear="all"><br>-- <br>Chris Wilson &lt;<a href="mailto:christopher.j.wilson@gmail.com">christopher.j.wilson@gmail.com</a>&gt;<br>