This is a bit tricky.

The type of 'f' is '[Int] -> IO [Int]', which means that the type of 'lst'
is 'IO [Int]'.

So fmap (+1) tries to add one to the [Int] underneath the 'IO' type
constructor.

You can either use two 'fmap's, the first to lift up to IO and the second to
lift into the list, or you can use monad notation:

> do
>   lst <- f [1,2,3,4]
>   return $ fmap (+1) lst

Does that make sense?

Take care,
Antoine

On Fri, Dec 17, 2010 at 11:04 AM, michael rice <nowg...@yahoo.com> wrote:

> I don't understand this error message. Haskell appears not to understand
> that 1 is a Num.
>
> Prelude> :t 1
> 1 :: (Num t) => t
> Prelude> :t [1,2,3,4,5]
> [1,2,3,4,5] :: (Num t) => [t]
> Prelude>
>
> Michael
>
> ===================
>
> f :: [Int] -> IO [Int]
> f lst = do return lst
>
> main = do let lst = f [1,2,3,4,5]
>           fmap (+1) lst
>
> ===============================
>
> Prelude> :l test
> [1 of 1] Compiling Main             ( test.hs, interpreted )
>
> test.hs:5:17:
>     No instance for (Num [Int])
>       arising from the literal `1' at test.hs:5:17
>     Possible fix: add an instance declaration for (Num [Int])
>     In the second argument of `(+)', namely `1'
>     In the first argument of `fmap', namely `(+ 1)'
>     In the expression: fmap (+ 1) lst
> Failed, modules loaded: none.
> Prelude>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to