[Haskell-beginners] Reversing the lines read from stdin

Daniel Fischer daniel.is.fischer at web.de
Thu Jan 28 15:56:43 EST 2010


Am Donnerstag 28 Januar 2010 21:44:04 schrieb Tim Perry:
> I wrote a simple program: it reads the contents from standard in and
> reverses the order of the lines. I imagine there are many cleaner ways
> to do this. Anybody willing to post some rewrites?
>
> Thanks,
> Tim
>
>
> main = interact reverseFile
> reverseFile s = unlines $ lines $ foldr combineStr [] (lines s)
> combineStr s1 s2 = s2 ++ "\n" ++ s1

main = interact (unlines . reverse . lines)

perhaps?


More information about the Beginners mailing list