7. What is a function? A function, as in math. (In particular, as in lambda calculus.) ((Ask Jeff Odell.))
8. Follow the Arrows add x y has a type of int -> int -> int In C#, this could be Func<int, int, int> (Actually, that’s Func<int,<Func<int, int>>>. We’ll see why in a moment….)
9. Functions are values, too. .NET 1.0 => delegates .NET 2.0 => anonymous delegates + generics .NET 3.0 => lambdas Higher-order functions accept a function as a parameter.
10. Immutability NO side effects! NO state! NO I/O! Functions take an input and return a result Image from One Year Bible Blog
13. Advantages Very easy to reason about Concurrency friendly Easy to compose:doubleSq x = square(double(x))doubleSq = double . square Foundation of Domain Specific Languages
14. Disadvantages Too much recursion can overflow the stack (without tail-call optimization, or TCO) High memory consumption from creating so many objects …
16. Referential transparency Replace a function with its value Efficiency with caching (a.k.a. memoization) Easier for programmers to understand ∴ Easier to reuse and test
17. So what? Moore’s Law is failing. Multiple CPUs / cores is the future. Controlling mutable state in concurrency is very hard …unless you have no mutable state!
18. Also, “Mock objects and dependency injection are just for people who don’t know math.”* ~ Erik Meijer, Microsoft * See the Silverlight Toolkit for test examples.
20. Func & Action Define your functions. Generics are important. Type-safety over many types.
21. Lists everywhere! Functional languages like Lisp build entirely on lists and maps (i.e. Dictionaries). Feel like you’ve seen this before?
22. Also by Erik Meijer! LINQ! Implementation of common functional programming functions over lists via IEnumerable. Select => map Where => filter Aggregate => fold / reduce SelectMany => bind / fmap, or “map then flatten”
24. Take it further Functions as data Closures => Capture external state for later Currying + Partial application =>Reduce dependencies Memoization => Run it again later
28. What didn’t we cover? Many more functional operators (LINQ) Managing mutable state from the environment LINQ to Observables, Continuations, etc. The “M” word