Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Let's talk about PureScript
Search
Kārlis Lauva
August 17, 2016
Programming
0
70
Let's talk about PureScript
Presentation at Frontend Meetup Riga, August 2016.
Kārlis Lauva
August 17, 2016
Tweet
Share
More Decks by Kārlis Lauva
See All by Kārlis Lauva
Going Full Monty with full.monty
karlis
1
91
The Transatlantic Struggle
karlis
0
61
Two Scoops of Scala
karlis
0
99
Valsts pārvaldes atvērto datu semantiskās integrācijas procesi
karlis
1
150
Tornado in 1 Hour (or Less)
karlis
4
180
Other Decks in Programming
See All in Programming
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
350
情報漏洩させないための設計
kubotak
3
650
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
110
Spatial Rendering for Apple Vision Pro
warrenm
0
120
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
return文におけるstd::moveについて
onihusube
1
1.2k
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
900
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
140
Zoneless Testing
rainerhahnekamp
0
120
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
230
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.3k
Rails Girls Zürich Keynote
gr2m
94
13k
Bash Introduction
62gerente
609
210k
We Have a Design System, Now What?
morganepeng
51
7.3k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
1
100
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Raft: Consensus for Rubyists
vanstee
137
6.7k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Producing Creativity
orderedlist
PRO
342
39k
Automating Front-end Workflow
addyosmani
1366
200k
Visualization
eitanlees
146
15k
Typedesign – Prime Four
hannesfritz
40
2.4k
Transcript
an exciting trip through history prelude
1936 Lambda Calculus is born
1990 A bunch of smart people start working Haskell
1995 Brendan Eich is hired by NetScape to write Scheme
for the browser
Spoiler alert: He doesn't write a Scheme for NetScape
2016
You shouldn't be sad.
Maybe those functional dudes got something right.
let's talk about purescript Kārlis Lauva @skazhy frontend rīga meetup,
2016
Hello. I write Clojure and dabble with other things This
is not a monad tutorial This is, like, my opinion
So, Haskell for the browser, eh
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"
None
(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();
Y
turns out, functional programming languages are really useful for web
things
but javascript too can be purely functional
None
let's discuss the bad parts
[Object object]
an *actual* type system
purescript makes this example boring
like, really boring
sketchy branching
None
None
pattern matching
data Behavior = KillHumans | BeNiceToHumans type Robot = {
naughty :: Boolean } interactWithHumans :: Robot -> Behavior interactWithHumans { naughty: true } = KillHumans interactWithHumans { naughty: false } = BeNiceToHumans
data Behavior = KillAllHumans | BeNiceToHumans | KillOnlyVapers type Robot
= { niceness :: Int } interactWithHumans :: Robot -> Behavior interactWithHumans { niceness: 0 } = KillAllHumans interactWithHumans { niceness: 1 } = KillOnlyVapers interactWithHumans _ = BeNiceToHumans
callback hell
monads
fetchRobots(function(response) { assembleFleet(function(robots) { if (robots) return robots; }, function(error
{ .. }); }, function(error) {... });
data RobotArmy = Army (List Robot) fetchRobots = do robotParts
<- get "/robotParts" robots <- assembleFleet robotParts return $ Army robots
None
does purescript survive in the real world?
yes.
None
ecosystem and tooling
psc short for "purescript compiler"
modules managed via bower
• build tool => pulp • hoogle for purescript =>
pursuit
purescript - javascript teamwork
back to killer robots
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 }
PS.Main.safeInteract(isCrazyMurderingRobot)();
but will purescript react?
yes.
ok, so what have we learned
so should we all switch to purescript today?
not _all_ of us
most of the internet runs on vanilla javascript just fine
(for years)
None
None
go check it out hack cool things
• purescript.org • karlis.me
thanks