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

Function Programming, The 1st Aid Kit PureScrip...

Yoan Ribeiro
September 14, 2017

Function Programming, The 1st Aid Kit PureScript(ed)

Functional Programming, the First-Aid Kit
Purescript(ed)
This Kit proposes to discuss these 3 main points:
- What is FP exactly?
- The differences between FP and other programming paradigms
- Basics of FP (recursion, lazy evaluation, purity and types)
All this with flavoured in PureScript, functional language inspired by Haskell which compiles to Javascript

Link of the meetup containing my talk and another interesting talk given by @bloodyowl (on twitter) about ReasonML (In French): https://www.youtube.com/watch?v=hbcEYBQ4x70

Yoan Ribeiro

September 14, 2017
Tweet

Other Decks in Programming

Transcript

  1. In In a nutshell What is FP? How is FP

    different from the others? The Basics of FP Wrapping up In
  2. Functional Programming (def) Programming Paradigm that treats computation as the

    evaluation of mathematical functions and avoids changing-state and mutable data. By Wikipedia
  3. For real now More like a style of programming; Expressions

    (statements); Recursion (iteration); Functions are King (or Queen). @yoanribeiro
  4. FP Style - Functions are King Functions are the building

    blocks of our programs; Functions are a mapping from input to output; Functions can be parameters and return other Functions. State does not (usually) enter in this equation. @yoanribeiro
  5. FP Style - Functions are King Functions can be parameters

    and return other Functions. @yoanribeiro
  6. Abstraction in OOP Objects are the end-goal when abstracting (shocker).

    We interact with them by using methods. Easy to represent and visualise. @yoanribeiro
  7. Abstraction in FP Functions are the end-goal when abstracting (shocker

    again). From these functions the types come naturally. Focused, by default, on the relations between the different components. @yoanribeiro
  8. Quick word about PureScript PureScript is a functional programming language

    inspired by Haskell (with major differences); Compiles to readable JS; Active community. http://www.purescript.org/
  9. Lazy VS Eager O1 - Only calculates the value when

    needed (Hello Memoisation); O2 - Calculates the value as soon as it is bounded to a variable. @yoanribeiro
  10. Types Our functions have a input type and an output

    type. Types can also be glued e.g. Tuple, Either (Union) A x B A + B @yoanribeiro
  11. Types in PureScript JS Primitive types: String, Boolean, Number Integer:

    Int is transformed into Number but operation are implemented differently. Array a : JS Array but all elem must have the same type Records : JS Objects, e.g type Person = { name :: String } Polymorphic types: forall a . List a @yoanribeiro
  12. Ad summam FP is a style of programming; FP mindset

    is useful in any programming language; Functions are cool: composition, pure & etc.
  13. Come to the Functional (Programming) Side FP encourages safe way

    of programming & quick prototyping FP tends to be more elegant than the others FP + Pattern matching = Heaven Immutable data => ¬ race-condition => Safe multithreading Easier to be parallelised Etc. @yoanribeiro