Let's talk about PureScript

Let's talk about PureScript

Presentation at Frontend Meetup Riga, August 2016.

085d620aca53f8b5a7630021747d9c9d?s=128

Kārlis Lauva

August 17, 2016
Tweet

Transcript

  1. an exciting trip through history prelude

  2. 1936 Lambda Calculus is born

  3. 1990 A bunch of smart people start working Haskell

  4. 1995 Brendan Eich is hired by NetScape to write Scheme

    for the browser
  5. Spoiler alert: He doesn't write a Scheme for NetScape

  6. 2016

  7. You shouldn't be sad.

  8. Maybe those functional dudes got something right.

  9. let's talk about purescript Kārlis Lauva @skazhy frontend rīga meetup,

    2016
  10. Hello. I write Clojure and dabble with other things This

    is not a monad tutorial This is, like, my opinion
  11. So, Haskell for the browser, eh

  12. module Main where import Prelude import Control.Monad.Eff import Control.Monad.Eff.Console sup

    :: String -> String sup g = "sup, " ++ g main :: forall e. Eff (console :: CONSOLE | e) Unit main = do log $ sup "world"
  13. None
  14. (function(exports) { "use strict"; var Prelude = PS["Prelude"]; var Control_Monad_Eff

    = PS["Control.Monad.Eff"]; var Control_Monad_Eff_Console = PS["Control.Monad.Eff.Console"]; var sup = function (g) { return "sup, " + g; }; var main = Control_Monad_Eff_Console.log(sup("world")); exports["main"] = main; exports["sup"] = sup;; })(PS["Main"] = PS["Main"] || {}); PS["Main"].main();
  15. Y

  16. turns out, functional programming languages are really useful for web

    things
  17. but javascript too can be purely functional

  18. None
  19. let's discuss the bad parts

  20. [Object object]

  21. an *actual* type system

  22. purescript makes this example boring

  23. like, really boring

  24. sketchy branching

  25. None
  26. None
  27. pattern matching

  28. data Behavior = KillHumans | BeNiceToHumans type Robot = {

    naughty :: Boolean } interactWithHumans :: Robot -> Behavior interactWithHumans { naughty: true } = KillHumans interactWithHumans { naughty: false } = BeNiceToHumans
  29. data Behavior = KillAllHumans | BeNiceToHumans | KillOnlyVapers type Robot

    = { niceness :: Int } interactWithHumans :: Robot -> Behavior interactWithHumans { niceness: 0 } = KillAllHumans interactWithHumans { niceness: 1 } = KillOnlyVapers interactWithHumans _ = BeNiceToHumans
  30. callback hell

  31. monads

  32. fetchRobots(function(response) { assembleFleet(function(robots) { if (robots) return robots; }, function(error

    { .. }); }, function(error) {... });
  33. data RobotArmy = Army (List Robot) fetchRobots = do robotParts

    <- get "/robotParts" robots <- assembleFleet robotParts return $ Army robots
  34. None
  35. does purescript survive in the real world?

  36. yes.

  37. None
  38. ecosystem and tooling

  39. psc short for "purescript compiler"

  40. modules managed via bower

  41. • build tool => pulp • hoogle for purescript =>

    pursuit
  42. purescript - javascript teamwork

  43. back to killer robots

  44. data Behavior = KillHumans | BeNiceToHumans instance showBehavior :: Show

    Behavior where show KillHumans = "kill all humans11" show BeNiceToHumans = "humans, you are pretty tite" type Robot = { naughty :: Boolean } interactWithHumans :: Robot -> Behavior interactWithHumans { naughty: true } = KillHumans interactWithHumans { naughty: false } = BeNiceToHumans safeInteract :: Boolean -> String safeInteract x = show $ interactWithHumans { crazyMurderer : x }
  45. PS.Main.safeInteract(isCrazyMurderingRobot)();

  46. but will purescript react?

  47. yes.

  48. ok, so what have we learned

  49. so should we all switch to purescript today?

  50. not _all_ of us

  51. most of the internet runs on vanilla javascript just fine

    (for years)
  52. None
  53. None
  54. go check it out hack cool things

  55. • purescript.org • karlis.me

  56. thanks