[Haskell-beginners] mapM etc.

Alexey G kreed131 at gmail.com
Fri Jul 1 22:48:24 CEST 2011


Try this:

> mapM (\x -> getDeviceInfo x >>= print . name) [0..10]


2011/7/1 Dennis Raddle <dennis.raddle at gmail.com>

> It's been about a year since I used Haskell and I'm rusty. I think I knew
> how to do this once, but I need a reminder.
>
> I've got some functions:
>
> getDeviceInfo :: Int -> IO DeviceInfo
>
> name :: DeviceInfo -> String
>
> I want to do something like
>
> func :: IO ()
> func = do
>   ds <- mapM getDeviceInfo [0..10]
>   mapM_ (print . name) ds
>
> Is there a way to combine 'getDeviceInfo', 'name', and 'print' in one line?
>
> Dennis
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110701/c929a57d/attachment.htm>


More information about the Beginners mailing list