Mundane Utility: A Functional Shell

Mundane Utility: A Functional Shell

Functional programming is a useful technique. We spend a lot of time discussing it in the context of hard, challenging or interesting problems, but no where nearly enough in the context of mundane problems.

The UNIX shell, or command line interpreter. A simple, but useful program too often mistaken as complex, or mysterious. Almost every programmer is exposed to shells from a users perspective, but far fewer have ever implemented one, or even know where to start.

This talk aims to be a fun look at using functional programming in and around a traditional, some would say mundane, system utility. We will work through the concepts involved with implementing your own shell, and live code our way to a basic functional shell implemented in Haskell.

From this talk, attendees will walk a way with a better understanding of a program they use every day, as well as ideas and inspiration around using functional programming to solve mundane programming problems.

NOTE: this is the lead in to a workshop https://github.com/markhibberd/xsh

42d9867a0fee0fa6de6534e9df0f1e9b?s=128

Mark Hibberd

May 08, 2017
Tweet

Transcript

  1. Mundane Utility by Mark Hibberd

  2. “Awesomeness put to mundane use” TV Tropes on Mundane Utility

  3. Unix Shell Userland Kernel Hardware

  4. How did we get here…

  5. How did we get here… firmware

  6. How did we get here… firmware boot loader

  7. How did we get here… firmware boot loader kernel

  8. How did we get here… firmware boot loader kernel init

  9. None
  10. How did we get here… firmware boot loader kernel init

  11. How did we get here… firmware boot loader kernel init

    getty note this is just one example sequence at this point onwards
  12. How did we get here… firmware boot loader kernel init

    getty login
  13. How did we get here… firmware boot loader kernel init

    getty login shell
  14. How did we get here… firmware boot loader kernel init

    getty login shell ls
  15. A shell…

  16. why? A shell…

  17. None
  18. A shell… Line Editing Command Parsing Command Expansion Process Management

    Builtins
  19. line editing… q w e r t y

  20. command parsing…

  21. command parsing… <program> ::= lists EOF | EOF <lists> ::=

    list | list <separator> list <list> ::= list | list <and> pipeline | list <or> pipeline <pipeline> ::= pipeline | pipeline <pipe> command <command> ::= word | command word <separator> ::= ; <and> ::= && <or> ::= || <pipe> ::= | <word> ::= …
  22. command parsing… character input

  23. command parsing… lexer

  24. command parsing… token stream

  25. command parsing… parser

  26. command parsing… program

  27. lexing words… word soft hard unquoted text variable text variable

  28. process management…

  29. ls | sort | uniq process management…

  30. process management… fork() ls | sort | uniq uniq sort

    ls xsh xsh xsh xsh
  31. fork() fork() ls | sort | uniq uniq sort ls

    xsh xsh xsh xsh process management…
  32. fork() fork() exec() ls | sort | uniq uniq sort

    ls xsh xsh xsh xsh process management…
  33. fork() fork() fork() exec() ls | sort | uniq uniq

    sort ls xsh xsh xsh xsh process management…
  34. fork() fork() fork() exec() exec() ls | sort | uniq

    uniq sort ls xsh xsh xsh xsh process management…
  35. fork() fork() fork() exec() exec() exec() ls | sort |

    uniq uniq sort ls xsh xsh xsh xsh process management…
  36. ls | sort | uniq xsh xsh xsh xsh uniq

    sort ls fork() process management…
  37. ls | sort | uniq xsh xsh xsh xsh uniq

    sort ls fork() fork() process management…
  38. ls | sort | uniq xsh xsh xsh xsh uniq

    sort ls fork() fork() fork() process management…
  39. ls | sort | uniq xsh xsh xsh xsh uniq

    sort ls fork() fork() fork() exec() process management…
  40. ls | sort | uniq xsh xsh xsh xsh uniq

    sort ls fork() fork() fork() exec() exec() process management…
  41. ls | sort | uniq xsh xsh xsh xsh uniq

    sort ls fork() fork() fork() exec() exec() exec() process management…
  42. ls | sort | uniq fork() xsh xsh xsh xsh

    ls sort uniq process management…
  43. ls | sort | uniq fork() exec() xsh xsh xsh

    xsh ls sort uniq process management…
  44. ls | sort | uniq fork() fork() exec() xsh xsh

    xsh xsh ls sort uniq process management…
  45. ls | sort | uniq fork() fork() exec() exec() xsh

    xsh xsh xsh ls sort uniq process management…
  46. ls | sort | uniq fork() fork() fork() exec() exec()

    xsh xsh xsh xsh ls sort uniq process management…
  47. ls | sort | uniq fork() fork() fork() exec() exec()

    exec() xsh xsh xsh xsh ls sort uniq process management…
  48. pushing limits

  49. workshop @ 1:15 https://github.com/markhibberd/xsh

  50. Mundane Utility by Mark Hibberd