Anzeige
Anzeige

Más contenido relacionado

Anzeige

Functional programming

  1. Functional Programming Bas Bossink April 2010
  2. Contents Introduction Definition History Taxonomy Features Functional concepts When to use it? When not to use it? Resources
  3. Introduction Disclaimer Inventory Anecdote About GFDL on github libre tools
  4. Definition Functions are central construct Functions are regular values passed around returned composed (partially) applied No variables but binding of values all variables are immutable
  5. Definition of a Function Functions are mathematical
  6. Example Figure 1:
  7. Non-example Figure 2:
  8. Definition of a Function Same input -> same output No side effects, pure
  9. History Lambda calculus Alonzo Church 1930s untyped lambda calculus simply typed lambda calculus Figure 3:
  10. Taxonomy Group functional languages across several axis: Statically typed / Dynamically typed Strong typing / Weak typing Lazy / Eager Single paradigm / Multi paradigm
  11. Taxonomy
  12. Taxonomy
  13. Features Read Eval Print Loop (REPL) Type inference (var on steroids) Pattern matching Algabraic data types Function composition Anonymous functions (lambda expressions) Closure
  14. Features Sequence Epressions (List Comprehensions) Partial function application (currying) Higher order functions (map, fold, filter)
  15. Funtional concepts Tail Recursion Continuation passing style Memoization
  16. Computation Expressions (Monads) Concept from mathematics, Category theory A triple: type constructor bind aka chain operation return aka inject operation
  17. Category a collection of elements a collection of morphisms (think function) a notion of composition of these morphisms Example Grp, Set, Hask
  18. Functor Transformation between categories Given category C, D, functor F F : C -> D f: A -> B then F(f) -> F(A) -> F(B) Examples: F: Grp -> Set, forgetful functor
  19. Monad Functor: M: C -> C unit: X -> M(X) join: M(M(X)) -> M(X)
  20. Monads class Monad m where (>>=) :: m a -> (a -> m b) -> m b return :: a -> m a instance Monad [] where return x = [x] xs >>= f = concat (map f xs)
  21. When to use it? stateless data-transformations calculation /scientific computing parrallellism
  22. When not to use it? a lotta state gui’s
  23. Resources F# Expert F# Wikibook Developer Center HubFs Haskell Real World Haskell (book) Real World Haskell online Haskell.org Haskell lectures Erik Meijer Yet another Haskell tutorial
  24. Labs Haskell F# fix code such that quickcheck/fscheck succeeds solutions on solution branch try euler project
Anzeige