Hi all,<br><br>I was looking around Stroustrup's website and found a simple program that he showed how standard library can be used to make the program succinct and safe. See <a href="http://www.research.att.com/~bs/bs_faq2.html#simple-program">http://www.research.att.com/~bs/bs_faq2.html#simple-program</a>. I wondered how a Haskell program equivalent to it looks like and I came up with the code below.<br>
<br><div style="margin-left: 40px; font-family: courier new,monospace;">import qualified Control.Exception as E<br><br>main = E.catch (interact reverseDouble) (\_ -> print "format error")<br><br>reverseDouble = unlines . doIt . words<br>
where doIt = intro . toStrings . reverse . toDoubles . input<br> toDoubles = map (read::String->Double)<br> toStrings = map show<br> input = takeWhile (/= "end")<br> intro l = ("read " ++ (show $ length l) ++ " elements") :<br>
"elements in reversed order" :<br></div><br>I'm not a Haskell expert and I am pretty sure that this is not the optimal form a Haskell program that's equivalent to the C++ one. So I would like to see, from the Haskell experts in this group, how else (of course better form) such a program can be written.<br>
<br>Thanks,<br>Ed<br><br><br>