[Haskell-beginners] single responsibility principle vs functional
Joe Van Dyk
joe at fixieconsulting.com
Wed Jan 27 19:45:30 EST 2010
I'm not saying to directly translate a OOP project to Haskell using
the same design, but rather to take the business requirements of the
OOP project and write them in Haskell.
(So, both versions do the same thing, but the design of them will be
On Wed, Jan 27, 2010 at 3:27 PM, Henk-Jan van Tuyl <hjgtuyl at chello.nl> wrote:
> I have the experience that you better start from scratch when learning a new
> programming paradigm, do not try to write object oriented programs in
> Haskell. A great description of how to use the functional programming
> paradigm can be found in "Why Functional Programming Matters" . Maybe
> also interesting is "The Monad.Reader/Issue3/Functional Programming vs
> Object Oriented Programming" .
>  http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html
> Henk-Jan van Tuyl
> On Wed, 27 Jan 2010 23:43:27 +0100, Joe Van Dyk <joe at fixieconsulting.com>
>> Thanks, I'm starting to get it.
>> Perhaps what I need to do is take a small standard OOP system and try
>> converting it to FP.
>> Or perhaps there's already examples of such a thing I could look at?
>> On Wed, Jan 27, 2010 at 11:43 AM, Stephen Blackheath [to
>> Haskell-Beginners] <mutilating.cauliflowers.stephen at blacksapphire.com>
>>> Classes in OOP have several purposes, one of which is to manage the
>>> of state so as to put a lid on the complexity that could result. The
>>> of an OOP class is usually a C program, and the outside is (ideally) a
>>> semi-functional program with interfaces that are simple at the level of
>>> abstraction where they operate. The single responsibility principle
>>> to stop the C programs getting big and messy, and to help the programmer
>>> build neat layers of abstraction on top of each other by having more
>>> abstract classes constructed out of less abstract ones.
>>> Functional programming essentially takes the C part away and makes the
>>> program into a layering of abstractions, even at the lowest level.
>>> An FP function more-or-less maps to an OOP class, and the reason why it
>>> be a much lighter-weight structure is because the need to manage mutation
>>> has been removed. I think the same principle applies, though - an FP
>>> function should have only one responsibility.
>>> Perhaps in FP the need for this principle to be explicitly stated and
>>> carefully observed is not so great, though. If an FP function does two
>>> things and can be split up, it's not such a big deal, because
>>> is easy in an FP language. By comparison in OOP, splitting a big messy
>>> class up is a lot of work with a great risk of breakage. This amplifies
>>> importance of applying the single responsibility principle before you
>>> writing the class.
>>> Joe Van Dyk wrote:
>>>> So I'm still pretty new to functional programming.
>>>> In OOP, you have the concept of each class having a
>>>> single-responsibility (or reason for changing). See
>>>> I'm having problems seeing how that concept maps to functional
>>>> programming. Perhaps it doesn't?
Joe Van Dyk
More information about the Beginners