Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Doing functional programming in C# is technically possible (well, any language that has function pointers or delegates equivalent can be "functional") -- but C# gets very very painful if you try to do much.</p> <p>Off the top of my head, in no particular order:</p> <ul> <li>Type inference <ul> <li>Only exists for locals now</li> <li>Should apply to pretty much everything</li> <li>The #1 problem I have with C# is this. Particularly when you declare a local function... Func&lt;...> = ouch. </li> </ul></li> <li>Full first class functions <ul> <li>Delegates aren't the answer, since they aren't structually equivalent. There's no canonical type to represent a function of a certain type. Ex: What is "increment"? Is it a Func? Is it a Converter? Is it something else? This in turn makes inference more complicated.</li> </ul></li> <li>Automatic generalization <ul> <li>Sucks to have to calculate and specify all the generic type parameters and their constraints</li> </ul></li> <li>Better support for immutability <ul> <li>Make it trivial to declare simple data types</li> <li>Copy-with-modify type stuff (var x = oldX { SomeField = newVal })</li> </ul></li> <li><strong>Tuples</strong> C# 7</li> <li>Discriminated unions (sum types)</li> <li><strong>Pattern matching</strong> C# 7 <ul> <li>Makes tuples and sum types much more valuable</li> <li>Allows more expression-oriented code</li> </ul></li> <li>General monad syntax <ul> <li><strong>Makes things like async code much easier to write</strong> C# 5</li> <li>After you've nested 2+ layers of BeginXXX/EndXXX, it gets quite ugly.</li> </ul></li> <li>Easy syntax for function blocks, so you don't end up with closing lines like "});});"</li> </ul> <p><em>Edit:</em> One more:</p> <ul> <li><p>Function composition</p> <ul> <li>Right now it's painful to do much of any sort of function composition. Currying, chaining, etc. LINQ doesn't get as hurt here because extension methods take the first parameter like an instance method. </li> </ul></li> <li><p><strong>C# should emit tail.call too.</strong> Not needed, the JIT will add tail calls itself as appropriate.</p></li> </ul> <p>Items in <strong>bold</strong> have been addressed since this answer was written.</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.
 

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