¿Alguna idea sobre el desarrollo de una forma de programación funcional para la resolución de problemas?

I have studied several articles, some chapters of books about FP and I would like to practice it a lot to make FP paradigm as part of my mind. But I still can't get it and it's really easy to doubt myself.

preguntado el 08 de enero de 11 a las 16:01

Do you have a question, one that can have an actual answer? -

Drake is asking for recommendations about the good ways to learn FP. -

4 Respuestas

To embrace functional programming, you must stop thinking of variables as memory locations whose values can be changed over and over again. Instead, think of your data as an immutable lump that is fed into a function, producing another immutable lump of data. If you have used UNIX (or DOS) tuberías, they work in just this way. The goal is to chain together a sequence of functions that transform the provided input into the desired output.

To practice this, I suggest tackling Proyecto Euler problems in your chosen functional language. If you have yet to choose a language, Haskell offers fewer non-functional distractions than most languages. However, consult otra pregunta SO para más opciones

After building a few functional pipelines, you will quickly find that you want to put functions together in ways more elaborate than simple chaining. This is where higher-level functions come into play, involving concepts like cartografía, plegable y zurra. After playing with those concepts, you might start to imagine even higher-level abstractions that go by names like monada y cirugía estética.

The key to this progression is to make sure that you restrict yourself to the functional style when tackling your practice problems. One way to do that is to force yourself to express solutions using only tácito (o sin puntos) formar.

contestado el 23 de mayo de 17 a las 15:05

Project Euler looks interesting, something like ACM ICPC in which I did enjoy problem solving (like IQ test). The big difference between Euler and ICPC seems that Euler doesn't require you submit the program :) - Drake Guan

edited: added the recommendation to practice using only point-free form - Alcance

To me, it looks like not that clear what tacit programming is. Can I say that point-free means there is nearly no local variables and variable assignment in the namespace of functions? - Drake Guan

I'm not sure what you mean by "in the namespace of functions" but, yes, point-free basically means that function arguments are not named explicitly within function definitions. This really forces one to think about the action of the functions themselves, rather than the shuffling of values around in memory locations. There are other benefits as well, beyond learning, that are covered in John Backus' excellent (but difficult) paper ¿Se puede liberar la programación del estilo von Neumann? - Alcance

Books aimed at beginner programmers teach the concepts and basics of functional programming along with a particular programming language. Books were my way into Lisp, ML/OCAML, and Haskell.

I'm not sure it's a matter of mindset. Some problems have cleaner solutions in pure functional and others in pure OO, etc. That's why many mainstream programming languages are evolving into multi-paradigm systems.

A personal opinion (something disliked here) is that it's easier to do functional in Python, C#, or Java, than it is to do statefull OO in Haskell, or OCAML. There are several hoops to jump before one even begins to grasp the concept and application of Mónadas.

Respondido el 08 de enero de 11 a las 20:01

Interestingly, I have been tasting FP in Python for months and it seems I just got something like, map/filter/reduce, comprehensive list, closure and list-oriented thinking. But nothing more. What I am thinking is how to shift my mind when facing some tasks having cleaner solutions in FP :) - Drake Guan

You can read the books about functional programming languages, and experiment, practice, and do the exercises in Python. There are also friendly programming environments for OCAML and Haskell. - Apalala

http://msdn.microsoft.com/en-us/library/bb669144.aspx

Gives some details about the difference with procedural programming.

You might want to check more (popular) reading from Douglas R Hofstadter, who has based a few books on the functional programming language LISP.

“Goedel, Escher, Bach” by D.R. Hofstadter, and of course Metamagical Themas, that included a chapter about recursion, and the solution of the Towers of Hanoi in Lisp. Things I read when I was a teenager and that got me started on programming.

Respondido el 08 de enero de 11 a las 23:01

Misses the (admittedly poorly-asked) question. Virtual -1 - user395760

Ok; extended my answer with some references to books. - Hace

GEB is too heavy reading for someone that just wants to get acquainted with FP. - Apalala

You may start with "How to design programs" by Felleisen et al. It's oriented towards problem solving, IIUC this is what you're after.

Respondido el 26 de enero de 11 a las 17:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.