[Haskell-cafe] Why is Haskell flagging this?
michael rice
nowgate at yahoo.com
Sun Dec 19 00:12:00 CET 2010
Here's (attached) a screen shot of the post I received from you.
There's your name after the "From:" at the top. Also, this post is a reply, so your message follows. Was there a mix up?
Michael
--- On Sat, 12/18/10, Thomas Davie <tom.davie at gmail.com> wrote:
From: Thomas Davie <tom.davie at gmail.com>
Subject: Re: [Haskell-cafe] Why is Haskell flagging this?
To: chrisdone at googlemail.com
Cc: "michael rice" <nowgate at yahoo.com>, haskell-cafe at haskell.org
Date: Saturday, December 18, 2010, 2:38 PM
On 17 Dec 2010, at 21:44, Christopher Done wrote:
On 17 December 2010 18:04, michael rice <nowgate at yahoo.com> wrote:
===================
f :: [Int] -> IO [Int]
f lst = do return lst
main = do let lst = f [1,2,3,4,5]
fmap (+1) lst The problem is that you are applying fmap to a type IO a.
fmap (+1) (return [1,2,3])
But to achieve the behaviour you expect, you need another fmap:
fmap (fmap (+1)) (return [1,2,3])
Which can be more neatly written with Conal's semantic editor cominators as
(fmap . fmap) (+1) (return [1,2,3])
Of course, I question why the list is put in the IO monad at all here... surely this would be much better
return $ fmap (+1) [1,2,3]
Finally, that has the wrong type for main... perhaps you meant to print it out?
main :: IO ()main = print $ fmap (+1) [1,2,3]
Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101218/e0bd8000/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot.png
Type: image/png
Size: 56044 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101218/e0bd8000/attachment-0001.png>
More information about the Haskell-Cafe
mailing list