$30 off During Our Annual Pro Sale. View Details »

Functional Programming - Why and How

Anupam
January 01, 2018

Functional Programming - Why and How

An introduction to Functional Programming, given during an FPNCR meetup at S&P offices in January 2018.

Anupam

January 01, 2018
Tweet

More Decks by Anupam

Other Decks in Technology

Transcript

  1. Why and How Functional Programming By Anupam Jain

  2. About Me •Organiser of FPNCR meetup •Programming professionally for over

    12 years •Mostly Javascript and Haskell •Built large production systems with Haskell •Some FOSS libraries - •Web UIs - (https://github.com/ajnsit/concur) •Servers - (https://github.com/ajnsit/wai-routes)
  3. What is Functional Programming •Functions Exist! •Functions are not Procedures.

    •Input and Output •First class
  4. What is Functional Programming •Functional •Declarative • Pure • Immutable

    • Statically Typed • Algebraic Data Types • Lazy • Concurrent • ……
  5. What is Functional Programming •Functional •Declarative • Pure • Immutable

    • Statically Typed • Algebraic Data Types • Lazy • Concurrent • …… Functions are the mode of abstraction
  6. What is Functional Programming •Functional •Declarative •Pure • Immutable •

    Statically Typed • Algebraic Data Types • Lazy • Concurrent • …… No sequence of steps
  7. What is Functional Programming •Functional •Declarative •Pure • Immutable •

    Statically Typed • Algebraic Data Types • Lazy • Concurrent • …… No side effects
  8. What is Functional Programming •Functional •Declarative • Pure •Immutable •

    Statically Typed • Algebraic Data Types • Lazy • Concurrent • …… No assignments
  9. What is Functional Programming •Functional •Declarative • Pure • Immutable

    •Statically Typed • Algebraic Data Types • Lazy • Concurrent • …… Potentially invalid programs are not compiled
  10. What is Functional Programming •Functional •Declarative • Pure • Immutable

    • Statically Typed •Algebraic Data Types • Lazy • Concurrent • …… User defined data types are sums of products
  11. What is Functional Programming •Functional •Declarative •Pure • Immutable •

    Statically Typed • Algebraic Data Types •Lazy • Concurrent • …… Order of evaluation is unknown
  12. The Sweet Spot Productivity Quality Resilience FP

  13. Productivity • Steep learning curve. But.. • Abstraction • Types

    • Isolation • APIs - Immutability, Laziness, Composition
  14. Productivity • Very few FP practitioners. But… • Supply vs

    Demand • High Quality Talent Pool • High Employee Satisfaction • Remote • Training
  15. Quality • Excellent Abstractions Pre-cooked for you • Excellent libraries

    for many things. Such as async programming.
  16. Quality • Static types hinder quick scripts. But.. • Easy

    Refactoring, checked at compile time • Slight Hyperbole - “If it compiles it works” • Reality - “Refactor without fear” • Let the computer help you help yourself • All this implies - Low Tech Debt
  17. Resilience • Forced to Manage Complexity • No Hidden State

    or Effects • Large class of bugs caught at Compile Time. • Great Refactoring Story.
  18. Functions • Functions exist! • Local and anonymous function definitions.

    • Higher order functions • First class functions
  19. Other things • Do notation. General purpose. • Alternative is

    a natural fit for many domains like parsing, gui construction. You can define many algorithmic functions on top like optional, many, foldMap etc. Almost forms a DSL. • Advanced techniques • Free Monads • Monad Transformers • Lens, Conduit, Pipes
  20. Via Haskell • Haskell Syntax • Haskell Semantics

  21. FPNCR •The Delhi/NCR Haskell and other Functional Programming Languages Meetup

    Group •https://www.meetup.com/DelhiNCR-Haskell-And- Functional-Programming-Languages-Group •Github- https://github.com/fpncr •Mailing List - https://groups.google.com/forum/#!forum/ fpncr •Slack - https://functionalprogramming.slack.com - #FPNCR