Slide 1

Slide 1 text

an exciting trip through history prelude

Slide 2

Slide 2 text

1936 Lambda Calculus is born

Slide 3

Slide 3 text

1990 A bunch of smart people start working Haskell

Slide 4

Slide 4 text

1995 Brendan Eich is hired by NetScape to write Scheme for the browser

Slide 5

Slide 5 text

Spoiler alert: He doesn't write a Scheme for NetScape

Slide 6

Slide 6 text

2016

Slide 7

Slide 7 text

You shouldn't be sad.

Slide 8

Slide 8 text

Maybe those functional dudes got something right.

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Hello. I write Clojure and dabble with other things This is not a monad tutorial This is, like, my opinion

Slide 11

Slide 11 text

So, Haskell for the browser, eh

Slide 12

Slide 12 text

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"

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

(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();

Slide 15

Slide 15 text

Y

Slide 16

Slide 16 text

turns out, functional programming languages are really useful for web things

Slide 17

Slide 17 text

but javascript too can be purely functional

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

let's discuss the bad parts

Slide 20

Slide 20 text

[Object object]

Slide 21

Slide 21 text

an *actual* type system

Slide 22

Slide 22 text

purescript makes this example boring

Slide 23

Slide 23 text

like, really boring

Slide 24

Slide 24 text

sketchy branching

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

pattern matching

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

data Behavior = KillAllHumans | BeNiceToHumans | KillOnlyVapers type Robot = { niceness :: Int } interactWithHumans :: Robot -> Behavior interactWithHumans { niceness: 0 } = KillAllHumans interactWithHumans { niceness: 1 } = KillOnlyVapers interactWithHumans _ = BeNiceToHumans

Slide 30

Slide 30 text

callback hell

Slide 31

Slide 31 text

monads

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

data RobotArmy = Army (List Robot) fetchRobots = do robotParts <- get "/robotParts" robots <- assembleFleet robotParts return $ Army robots

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

does purescript survive in the real world?

Slide 36

Slide 36 text

yes.

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

ecosystem and tooling

Slide 39

Slide 39 text

psc short for "purescript compiler"

Slide 40

Slide 40 text

modules managed via bower

Slide 41

Slide 41 text

• build tool => pulp • hoogle for purescript => pursuit

Slide 42

Slide 42 text

purescript - javascript teamwork

Slide 43

Slide 43 text

back to killer robots

Slide 44

Slide 44 text

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 }

Slide 45

Slide 45 text

PS.Main.safeInteract(isCrazyMurderingRobot)();

Slide 46

Slide 46 text

but will purescript react?

Slide 47

Slide 47 text

yes.

Slide 48

Slide 48 text

ok, so what have we learned

Slide 49

Slide 49 text

so should we all switch to purescript today?

Slide 50

Slide 50 text

not _all_ of us

Slide 51

Slide 51 text

most of the internet runs on vanilla javascript just fine (for years)

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

go check it out hack cool things

Slide 55

Slide 55 text

• purescript.org • karlis.me

Slide 56

Slide 56 text

thanks