[Haskell-beginners] How to think like a functional programmer?

Henning Diedrich hd2010 at eonblast.com
Thu May 26 20:31:33 CEST 2011


On 5/26/11 6:27 PM, Costello, Roger L. wrote:
>
> Hi Folks,
>
> I am working on a project and am trying hard to write the code in a 
> functional style.
>
> Sadly, upon reviewing what I've written, I realize that I am not 
> succeeding. I just devised a recipe for solving the problem and then 
> created functions corresponding to steps in the recipe.  I am still 
> thinking imperatively, not functionally.
>
> Is there a book or article that describes how to approach problems 
> from a functional mindset?
>
> How did you "flip the switch" in your brain to the functional mindset?
>

Hi Roger,

reminding oneself to take it literal, I found can be quite clarifying.

At the core of it, I found it helps to "avoid thinking state", i.e. 
putting stuff into variables. If you find yourself doing that a lot, 
it's a sign for the wrong track. You'll find, again and again, you don't 
need to keep that state. Just pass up the result of a call.

Inversely, avoid "lines that do not deliver a result", which "just do 
something". Or, to be precise, note when you don't use a result.

Taking "functional programming" literal, you'd try thinking about the 
entire problem as but nested function calls with no intermediary state 
holders, rather than "implicitly  tacting state tables", if that makes 
any sense.

Best,
Henning

> /Roger
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110526/cc6cb43a/attachment.htm>


More information about the Beginners mailing list