[Haskell-cafe] Re: turning an imperative loop to Haskell
Stefan O'Rear
stefanor at cox.net
Thu Sep 6 16:45:31 EDT 2007
On Thu, Sep 06, 2007 at 03:42:50PM +0200, apfelmus wrote:
> Dougal Stanton wrote:
>> To create an infinite list where each f(u) depends on the previous u,
>> with a single seed value, use 'iterate':
>
>> main = mapM_ (uncurry (printf "%d %f\n")) (zip [1..50] (iterate f 3))
>
> How about
>
> main = sequence_ $ zipWith (printf "%d %f\n") [1..50] (iterate f 3)
Better yet:
main = zipWithM_ (printf "%d %f\n") [1..50] (iterate f 3)
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070906/619c0245/attachment.bin
More information about the Haskell-Cafe
mailing list