[Haskell-beginners] How to think like a functional programmer?
Iñaki Garay
igarai at gmail.com
Thu May 26 19:14:44 CEST 2011
> 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?
Examples.
Read lots of code. Don't worry if you don't understand all of it. But
don't just 'look' at it, run it in your mind.
Programming is like writing in that just like a novel writer, you read
10x the amount you write.
Rewrite the same code as you learn, note the differences.
Others will provide better recommendations than I wtr recommended sources.
Think of your problem not in term of what it does, but what data it
handles, and what it does to it.
Design your program as a set of boxes consuming and producing data,
then implement the boxes as functions.
If your data needs to be transformed in succesive steps, that's
sequential computation and part of the problem's nature, not
necessarily a result of an imperative mindset.
You can implement it with composed functions.
Functional programming can free you from having to deal with certain
'bookkeeping' aspects of imperative programming, but it doesn't free
you from having to design a solution to the program.
e.g mapping over a sequence is better than having to write a loop and
control iteration, but you still had to think "do/apply X to all these
Y".
good luck,
Iñaki Garay.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/GMU d- s:- a25 C++ UL+++ P--- E- W+ PS+++ PE- Y+ t++ 5+ tv- b++
DI+ D--- G e h! r y++
------END GEEK CODE BLOCK------
More information about the Beginners
mailing list