Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A related question was asked before: <a href="https://stackoverflow.com/questions/327955/does-functional-programming-replace-gof-design-patterns">"Does functional programming replace GoF design patterns"</a>, with great responses.</p> <p>The equivalent of "design patterns" is very vague in FP. In general, every time you see a "pattern" in your code you should create something to cover all of its uses in a uniform way. Often it will be a higher-order function.</p> <p>For example, the following C code</p> <pre><code>for (int i = 0; i &lt; n; i++) if (a[i] == 42) return true; return false; </code></pre> <p>can be thought of some basic "design pattern" - checking if there's some special element on the list. This snippet could appear many times in code with different conditions. In FP, you simply use a higher order function several times. It's not a "pattern" anymore.</p> <p>Functional programming has its own practices, but they are much different from "design patterns" in OOP. They include use of polymorphism, lists, higher-order functions, immutability/purity, laziness [not all are essential or specific to FP]... See also<a href="https://stackoverflow.com/questions/1112773/what-are-the-core-concepts-in-functional-programming/1112966#1112966"> "what are core concepts of FP"</a>. Also, type classes (Haskell), modules and functors (OCaml), <a href="http://marijn.haverbeke.nl/cps/" rel="nofollow noreferrer">continuations</a>, <a href="http://haskell.org/haskellwiki/Monad" rel="nofollow noreferrer">monads</a>, <a href="http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf" rel="nofollow noreferrer">zippers</a>, <a href="http://apfelmus.nfshost.com/monoid-fingertree.html" rel="nofollow noreferrer">finger trees</a>, <a href="http://blog.sigfpe.com/2009/01/haskell-monoids-and-their-uses.html" rel="nofollow noreferrer">monoids</a>, <a href="http://www.haskell.org/arrows/" rel="nofollow noreferrer">arrows</a>, <a href="http://en.wikibooks.org/wiki/Haskell/Applicative_Functors" rel="nofollow noreferrer">applicative functors</a>, <a href="http://en.wikibooks.org/wiki/Haskell/Monad_transformers" rel="nofollow noreferrer">monad transformers</a>, many <a href="http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf" rel="nofollow noreferrer">purely functional data structures</a> (<a href="http://rads.stackoverflow.com/amzn/click/0521663504" rel="nofollow noreferrer">book</a>) etc. <a href="http://www.haskell.org/haskellwiki/Research_papers/Functional_pearls" rel="nofollow noreferrer">Functional pearls</a>, already mentioned by Randall Schulz, form a very rich resource of FP at its best.</p> <p>To learn how to write idiomatic code, any book/resource on a functional programming language will suffice IMHO (for example, <a href="http://book.realworldhaskell.org/" rel="nofollow noreferrer">RWH</a> and <a href="http://learnyouahaskell.com/" rel="nofollow noreferrer">LYAH</a>); differences between thinking imperatively and functionally are always explained there.</p> <p>In dynamic languages, Jeff Foster's link is a good collection; <a href="https://stackoverflow.com/questions/1524750/what-is-your-favourite-cleverly-written-functional-code/1551144#1551144">here</a> is a very clever use of memoization in JavaScript that could be considered a "design pattern".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload