Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fn.py: ideas & internals

Fn.py: ideas & internals

Fn.py library (https://github.com/kachayev/fn.py): key ideas and internal implementation details for functional programmers

Avatar for Oleksii Kachaiev

Oleksii Kachaiev

March 27, 2013
Tweet

More Decks by Oleksii Kachaiev

Other Decks in Programming

Transcript

  1. About me • Alexey Kachayev • CTO at KitApps Inc.

    • Open source activist • Functional programming advocate • Erlang, Python, Scala, Clojure, Go, Haskell • @kachayev • github.com/kachayev • kachayev at gmail.com Wednesday, March 27, 13
  2. About Python • minimalistic syntax • dynamically typed • imperative

    (by design) • “multi paradigm” • functions are variables • lambdas • iterators, generators, decorators, ... • mutable data types (mostly) Wednesday, March 27, 13
  3. About Fn.py • enjoy FP in Python • developed on

    my own talks materials • not only proof of concept • tremendous support from community Wednesday, March 27, 13
  4. Overview • Scala-style lambdas • Stream and infinite sequences declaration

    • TCO / trampolines • Itertools recipes • Option monad • Python 2/3 unification for functional stuff Wednesday, March 27, 13
  5. Why? • Code readability • Improve you vision • Keyboard

    will work longer Wednesday, March 27, 13
  6. How? • _Callable class • shortcut instance • overloaded operators

    • each instance - unary or double-side operations tree Wednesday, March 27, 13
  7. What? • Lazy evaluated list • Composable producers • Any

    number of consumers • All consumers share one iterable origin • Infinite (potentially) sequence Wednesday, March 27, 13
  8. Tail call optimization “I don't believe in recursion as the

    basis of all programming. This is a fundamental belief of certain computer scientists, especially those who love Scheme and like to teach programming by starting with a "cons" cell and recursion.” Guido van Rossum Wednesday, March 27, 13
  9. Recursion = Induction recursion = induction basis + step while

    loop = induction basis + step Wednesday, March 27, 13
  10. What? • analog = list with 1 or 0 elements

    • functor + fmap • monadic flatMap operation • “retry” computations Wednesday, March 27, 13
  11. When? • computations that may fail • heavy execution branching

    (if/else/try/etc) Wednesday, March 27, 13