[Haskell-cafe] [IO Int] -> IO [Int]
Magnus Therning
magnus at therning.org
Sun May 6 06:01:54 EDT 2007
On Fri, May 04, 2007 at 19:23:16 +0200, Phlex wrote:
>Hello all,
>
>I'm trying to learn haskell, so here's is my first newbie question.
>I hope this list is appropriate for such help requests.
>
>I'm trying to write a function with the signature [IO Int] -> IO [Int]
>
>Here is my first attempt :
>
>conv :: [IO Int] -> IO [Int]
>conv l = do val <- (head l)
> return (val : (conv (tail l)))
>
>This does not work as I'm consing an Int to an (IO [Int]).
>So I tried this :
>
>conv2 :: [IO Int] -> IO [Int]
>conv2 l = do val <- (head l)
> rest <- (conv2 (tail l))
> return (val : rest)
>
>That works, but it won't work for infinite lists.
>How could I achieve the desired result ?
I had a similar problem a little while back. I also asked on this list
and maybe that discussion[1] can illuminate the issue. I also put an
entry on my blog afterwards in an attempt to capture my understanding of
it all[2].
/M
[1]: http://www.haskell.org/pipermail/haskell-cafe/2007-January/021367.html
[2]: http://therning.org/magnus/archives/249
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnus at therning.org Jabber: magnus.therning at gmail.com
http://therning.org/magnus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070506/e36909b9/attachment.bin
More information about the Haskell-Cafe
mailing list