Hi all,<br><br>I was looking around Stroustrup&#39;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) (\_ -&gt; print &quot;format error&quot;)<br><br>reverseDouble = unlines . doIt . words<br>
&nbsp;&nbsp; where doIt = intro . toStrings . reverse . toDoubles . input<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; toDoubles = map (read::String-&gt;Double)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; toStrings = map show<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; input = takeWhile (/= &quot;end&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intro l = (&quot;read &quot; ++ (show $ length l) ++ &quot; elements&quot;) :<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;elements in reversed order&quot; :<br></div><br>I&#39;m not a Haskell expert and I am pretty sure that this is not the optimal form a Haskell program that&#39;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>