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

The Return of Stream I/O

The Return of Stream I/O

The Frontend community is remarkably shifting towards functional programming, with tools like React, Redux, Immutable.js and Elm becoming mainstream. In the early years of Haskell, there were three I/O models: Monads, Continuations, and Streams. While the Monadic I/O has been established as the standard in Haskell, we are seeing the resurgence of variations of Stream I/O in Frontend, through tools like Cycle.js and Elm. In this talk we will explore the benefits and downsides of Stream I/O, and what it promises for the future.

André Staltz

October 04, 2016
Tweet

More Decks by André Staltz

Other Decks in Programming

Transcript

  1. @andrestaltz
    The Return of Stream I/O

    View full-size slide

  2. Cycle.js.org
    A functional and reactive JavaScript framework 

    for cleaner code

    View full-size slide

  3. Haskell
    A pure functional
    programming language

    View full-size slide

  4. Haskell
    A pure functional
    programming language
    Logic
    Effects

    View full-size slide

  5. Haskell
    A pure functional
    programming language
    Logic
    Effects

    View full-size slide

  6. Logic
    Effects
    Monadic I/O
    Stream I/O
    Continuation I/O

    View full-size slide

  7. Logic
    Effects
    Monadic I/O
    Stream I/O
    Continuation I/O

    View full-size slide

  8. Logic
    Effects
    Monadic I/O

    View full-size slide

  9. Program
    Compiler, binary

    View full-size slide

  10. Logic
    Effects
    Stream I/O

    View full-size slide

  11. Program
    binary
    Operating
    System

    View full-size slide

  12. Program
    binary
    Operating
    System
    Requests
    "Write" msgs

    View full-size slide

  13. Program
    binary
    Operating
    System
    Requests
    Responses
    "Write" msgs
    "Read" msgs

    View full-size slide

  14. Program
    binary
    Operating
    System
    Requests
    Responses
    "Write" msgs
    "Read" msgs

    View full-size slide

  15. Reactive system
    versus

    Transformational system

    View full-size slide

  16. "A transformational system repeatedly waits for
    all its inputs to arrive, carries out some
    processing, and outputs the results when the
    processing is done."
    (1998)

    View full-size slide

  17. (start)

    Inputs
    Processing
    Output

    (done)

    View full-size slide

  18. Examples:


    Compiler

    UNIX commands

    View full-size slide

  19. "A reactive system continuously interacts with
    its environment, using inputs and outputs that
    are either continuous in time or discrete. The
    inputs and outputs are often asynchronous,
    meaning that they may arrive or change values
    unpredictably at any point in time."

    View full-size slide

  20. Input
    Processing
    Output

    View full-size slide

  21. Examples:


    Real-time systems
    User interfaces
    Websites
    Servers

    View full-size slide

  22. 1990
    Reactive programs
    Transformational programs
    2000 2010

    View full-size slide

  23. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript

    View full-size slide

  24. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Haskell

    Stream I/O

    View full-size slide

  25. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Monadic I/O good for 

    transformational programs

    View full-size slide

  26. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Haskell

    Monadic I/O

    View full-size slide

  27. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Multimedia

    View full-size slide

  28. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Period of
    confusion

    View full-size slide

  29. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Period of
    confusion

    View full-size slide

  30. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Shared-memory
    concurrency

    View full-size slide

  31. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Shared-memory
    concurrency

    View full-size slide

  32. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Early JavaScript

    apps

    View full-size slide

  33. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Early JavaScript

    apps

    View full-size slide

  34. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript

    View full-size slide

  35. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Asynchronous

    Continuous interaction

    View full-size slide

  36. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Asynchronous

    Continuous interaction

    View full-size slide

  37. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010
    Java
    JavaScript
    Message passing

    concurrency

    View full-size slide

  38. Program
    binary
    Operating
    System
    Requests
    Responses
    Stream I/O
    Message passing
    Lazy lists

    Blocking

    View full-size slide

  39. Program
    binary
    Operating
    System
    Requests
    Responses
    "Stream I/O"
    Message passing
    Lazy lists Streams

    Blocking Asynchronous

    View full-size slide

  40. Program
    binary
    Operating
    System
    Requests
    Responses
    Message passing
    Streams

    Asynchronous
    Cycle.js

    View full-size slide

  41. Stream of DOM events
    Stream of actions
    Stream of state
    Stream of reducers
    Stream of markup to the DOM

    View full-size slide

  42. Asynchronous message passing
    User interfaces or any reactive system
    Separation of concerns

    Handling question-and-answer I/O
    Cycle.js

    View full-size slide

  43. Elm
    program
    Elm
    runtime
    Task
    Result
    "Do this and then 

    that and tell me the

    result"

    View full-size slide

  44. Task: Monadic I/O
    Msg and Cmd: "Stream I/O"
    Elm

    View full-size slide

  45. Transformational 

    subprogram with Monadic I/O
    Reactive program

    with "Stream I/O"
    Elm

    View full-size slide

  46. Store Components
    State
    Action
    Flux

    View full-size slide

  47. Message passing

    +

    purely functional

    =

    "Stream I/O"?

    View full-size slide

  48. 1990
    Reactive programs
    Transformational programs
    2000 2010

    View full-size slide

  49. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010

    View full-size slide

  50. 1990
    Pascal
    FORTRAN
    BASIC
    C
    Reactive programs
    Transformational programs
    2000 2010

    View full-size slide

  51. 1990
    Pascal
    FORTRAN
    BASIC
    Java
    JavaScript
    Ruby
    C#
    C
    Reactive programs
    Transformational programs
    2000 2010

    View full-size slide

  52. 1990
    Pascal
    FORTRAN
    BASIC
    Java
    JavaScript
    Ruby
    C#
    C
    Reactive programs
    Transformational programs
    2000 2010

    View full-size slide

  53. 1990
    Pascal
    FORTRAN
    BASIC
    Java
    JavaScript
    Ruby
    C#
    C
    Reactive programs
    Transformational programs
    2000 2010
    Elm
    Elixir
    Clojure
    Dart

    View full-size slide

  54. 1990
    Pascal
    FORTRAN
    BASIC
    Java
    JavaScript
    Ruby
    C#
    C
    Reactive programs
    Transformational programs
    2000 2010
    Elm
    Elixir
    Clojure
    Dart
    Asynchronous
    Message passing
    Event-driven

    View full-size slide

  55. Framework Concurrency
    Cycle.js Message passing
    React / Redux Message passing
    Elm Message passing
    Vue.js (Vuex) Message passing
    Angular v1 ($scope) Shared-memory
    ngrx Message passing

    View full-size slide

  56. Framework Paradigm
    Cycle.js Wannabe functional
    React / Redux Wannabe functional
    Elm Functional
    Vue.js (Vuex) OOP
    Angular v1 ($scope) OOP
    ngrx Wannabe functional

    View full-size slide

  57. The future is
    functional, event-driven
    message passing concurrent
    programming

    View full-size slide

  58. Thank you 

    #

    View full-size slide