[Haskell-begin] Using read, reads...

Henk-Jan van Tuyl hjgtuyl at chello.nl
Mon Jul 21 15:14:37 EDT 2008


On Mon, 21 Jul 2008 06:51:27 +0200, Felipe Lessa <felipe.lessa at gmail.com>
wrote:
> On Sun, Jul 20, 2008 at 10:30 PM, Rafael Gustavo da Cunha Pereira
> Pinto <rafaelgcpp at gmail.com> wrote:
>
> convert :: String -> [Int]
> convert = map read . words
>
> read :: FilePath -> IO [[Int]]
> read fp = (map convert . lines) `fmap` readFile fp
>

If a single list of Ints is OK, the code can be much simpler:

> read' :: FilePath -> IO [Int]
> read' fp = (map read . words) `fmap` readFile fp


-- 
Met vriendelijke groet,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--



More information about the Beginners mailing list