<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi, all.<br><br>Plenty of answers. Thank you.<br><br>Putting the list in the IO monad was deliberate. Another one I was looking at was<br><br>f :: String -> IO String<br>f s = do return s<br><br>main = do ios <- f "hello"<br> fmap tail ios<br><br>which worked fine<br><br>So, the big error was trying to add 1 + [1,2,3,4,5].<br><br>I considered that I needed an additional fmap and thought I had tried<br><br>fmap (fmap (1+)) iol<br><br>but must have messed it up, because I got an error. I guess I was on the right track.<br><br>I like to try various combinations to test my understanding. It's kind of embarrassing when I get stumped by something simple like this, but that's how one learns.<br><br>Thanks again,<br><br>Michael<br><br>--- On Fri, 12/17/10, Daniel Fischer
<daniel.is.fischer@googlemail.com> wrote:<br><br><br> From: Daniel Fischer <daniel.is.fischer@googlemail.com><br> Subject: Re: [Haskell-cafe] Why is Haskell flagging this?<br> To: haskell-cafe@haskell.org<br> Cc: "michael rice" <nowgate@yahoo.com><br> Date: Friday, December 17, 2010, 4:24 PM<br><br> On Friday 17 December 2010 18:04:20, michael rice wrote:<br> > I don't understand this error message. Haskell appears not to understand<br> > that 1 is a Num.<br> ><br> > Prelude> :t 1<br> > 1 :: (Num t) => t<br> > Prelude> :t [1,2,3,4,5]<br> > [1,2,3,4,5] :: (Num t) => [t]<br> > Prelude><br> ><br> >
Michael<br> ><br> > ===================<br> ><br> > f :: [Int] -> IO [Int]<br> > f lst = do return lst<br> ><br> > main = do let lst = f [1,2,3,4,5]<br> > fmap (+1) lst<br><br> The fmap is relative to IO, your code is equivalent to<br><br> do let lst = (return [1,2,3,4,5])<br> fmap (+1) lst<br><br> ~><br><br> fmap (+1) (return [1,2,3,4,5])<br><br> ~><br><br> do lst <- return [1,2,3,4,5]<br> return $ (+1) lst<br><br> but there's no instance Num [Int] in scope<br><br> You probably
meant<br><br> do let lst = f [1,2,3,4,5]<br> fmap (map (+1)) lst<br><br> ><br> > ===============================<br> ><br> > Prelude> :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' at test.hs:5:17<br> > Possible fix: add an instance declaration for (Num [Int])<br> > In the second argument of `(+)', namely `1'<br> > In the first argument of
`fmap', namely `(+ 1)'<br> > In the expression: fmap (+ 1) lst<br> > Failed, modules loaded: none.<br> > Prelude><br><br><br>--- On <b>Fri, 12/17/10, Daniel Fischer <i><daniel.is.fischer@googlemail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Daniel Fischer <daniel.is.fischer@googlemail.com><br>Subject: Re: [Haskell-cafe] Why is Haskell flagging this?<br>To: haskell-cafe@haskell.org<br>Cc: "michael rice" <nowgate@yahoo.com><br>Date: Friday, December 17, 2010, 4:24 PM<br><br><div class="plainMail">On Friday 17 December 2010 18:04:20, michael rice wrote:<br>> I don't understand this error message. Haskell appears not to understand<br>> that 1 is a Num.<br>><br>> Prelude> :t 1<br>> 1 :: (Num t) => t<br>> Prelude> :t [1,2,3,4,5]<br>>
[1,2,3,4,5] :: (Num t) => [t]<br>> Prelude><br>><br>> Michael<br>><br>> ===================<br>><br>> f :: [Int] -> IO [Int]<br>> f lst = do return lst<br>><br>> main = do let lst = f [1,2,3,4,5]<br>> fmap (+1) lst<br><br>The fmap is relative to IO, your code is equivalent to<br><br>do let lst = (return [1,2,3,4,5])<br> fmap (+1) lst<br><br>~><br><br>fmap (+1) (return [1,2,3,4,5])<br><br>~><br><br>do lst <- return [1,2,3,4,5]<br> return $ (+1) lst<br><br>but there's no instance Num [Int] in scope<br><br>You probably meant<br><br>do let lst = f [1,2,3,4,5]<br> fmap (map (+1)) lst<br><br>><br>> ===============================<br>><br>> Prelude> :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' at test.hs:5:17<br>> Possible fix: add an instance declaration for (Num [Int])<br>> In the second argument of `(+)', namely `1'<br>> In the first argument of `fmap', namely `(+ 1)'<br>> In the expression: fmap (+ 1) lst<br>> Failed, modules loaded: none.<br>> Prelude><br><br></div></blockquote></td></tr></table><br>