tag:blogger.com,1999:blog-8976038770606708499.post8753816904494658588..comments2024-03-15T08:27:35.878+01:00Comments on Graphics and FPL: Regular imperative statements versus FPL abstractionsAnonymoushttp://www.blogger.com/profile/06180476773002153033noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-8976038770606708499.post-47662421580022383462014-02-25T18:25:53.863+01:002014-02-25T18:25:53.863+01:00There is std::accumulate (and have been for a whil...There is std::accumulate (and have been for a while actually) in C++, just to point that abstractions exists there as well. Actually C++ (const) iterators are a way to make the very same stuff you can achieve with Foldable/Traversable from Haskell, at about the same abstraction level.<br /><br />Also you have a semicolon after for loop making the body empty and first C++ example not compilable. And as you use C++11 auto, you could use range-based for loop (if you don’t want to use std::accumulate for some reason).<br /><br />In conditional execution example, I would extract string generation into own function. You do it Haskell example, so why not to do it C++ as well?<br /><br />Using exceptions for handling “not-happy” path is totally valid thing in C++. It’s way better than testing result value for each function call (as the Maybe’s or Either’s bind does, but that’s hidden behind the abstraction). Computing with exceptions is like computing in exists e : Exception, Either e -monad.<br /><br />Maybe the choice of C++ for imperative language is not the best possible. You can build powerful abstractions in C++ as well. Bare C would be much illustrative.phadejhttps://www.blogger.com/profile/03895991745557942711noreply@blogger.com