Hi all, 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 http://www.research.att.com/~bs/bs_faq2.html#simple-program. I wondered how a Haskell program equivalent to it looks like and I came up with the code below.
import qualified Control.Exception as E main = E.catch (interact reverseDouble) (\_ -> print "format error") reverseDouble = unlines . doIt . words where doIt = intro . toStrings . reverse . toDoubles . input toDoubles = map (read::String->Double) toStrings = map show input = takeWhile (/= "end") intro l = ("read " ++ (show $ length l) ++ " elements") : "elements in reversed order" : 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. Thanks, Ed
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe