Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PureScript
Search
Brian McKenna
May 19, 2014
Programming
600
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PureScript
For Full Stack Boulder.
Brian McKenna
May 19, 2014
Transcript
29 slides
None
Goals
· Writing JavaScript · Functional programming · Small output ·
Small language
Transpilers Are Awesome
· Compile step! · ES6 is bad! · Small output,
take output and forget
Resources
· purescript.org · try.purescript.org · purescript.readthedocs.org
Types
data Person = Person String Number sayHello :: Person ->
String sayHello (Person name age) = "Hello " ++ name ++ ", you are " ++ show age ++ " years old"
var PS = PS || {}; PS.Person = (function ()
{ "use strict"; var Prelude = PS.Prelude; var Person = function (value0) { return function (value1) { return { ctor: "Person.Person", values: [ value0, value1 ] }; }; }; var sayHello = function (_1) { return "Hello " + _1.values[0] + ", you are " + Prelude.show(Prelude.showNumber({}))(_1.values[1]) + " years old"; }; return { Person: Person, sayHello: sayHello }; })();
var brian = PS.Person.Person("Brian")(24); console.log(PS.Person.sayHello(brian));
Extensible records
addXY :: forall r. { x :: Number, y ::
Number | r } -> Number addXY o = o.x + o.y -- Error: Object does not have property y -- x :: Number -- x = addXY { x: 1 } xy :: Number xy = addXY { x: 1, y: 2 } xyz :: Number xyz = addXY { x: 1, y: 2, z: 3 }
Interoperating
foreign import showBool "function showBool(b) {\ \ return b.toString();\ \}"
:: Boolean -> String
Type classes
class ToString s where toString :: s -> String instance
boolTS :: ToString Boolean where toString = showBool instance numberTS :: ToString Number where toString = showNumber main = trace (toString true ++ toString 10)
Tools
· npm · Grunt/Gulp · Bower
module.exports = function(grunt) { grunt.initConfig({ libFiles: [ "src/**/*.purs", "bower_components/purescript-*/src/**/*.purs", ],
clean: ["output"], pscMake: ["<%=libFiles%>"], dotPsci: ["<%=libFiles%>"], docgen: { readme: { src: "src/**/*.purs", dest: "README.md" } } }); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-purescript"); grunt.registerTask("make", ["pscMake", "dotPsci", "docgen"]); grunt.registerTask("default", ["make"]); };
{ "name": "purescript-streams", "homepage": "https://github.com/purescript-contrib/purescript-streams", "description": "Compositional, streaming I/O library",
"keywords": [ "purescript" ], "license": "MIT", "ignore": [ "**/.*", "bower_components", "node_modules", "output", "tests", "tmp", "bower.json", "Gruntfile.js", "package.json" ], "dependencies": { "purescript-monoid": ">=0.1.1", "purescript-tuples": "*", "purescript-task": "*" } }
Libraries
· purescript-react · purescript-reactive · purescript-canvas · purescript-jquery · purescript-quickcheck
· purescript-streams
counter = mkUI spec { getInitialState = return 0 }
do val <- readState return $ DOM.p { className: "Counter", onClick: handle incrementCounter } [ DOM.text (show val), DOM.text " Click me to increment!" ]
testConst :: Number -> Number -> Number -> Boolean testConst
a b c = const a b == const a c main :: Eff (trace :: Trace) {} main = quickCheck testConst
None
snowflake :: Number -> Drawing snowflake n = go <<<
go <<< go $ circle where go = everywhere replace replace (Arc { cx = cx, cy = cy, r = r }) = Composite $ flip map (range 0 (n - 1)) $ \i -> let theta = i / n * Math.pi * 2 in Arc { cx: cx + r * 0.7 * Math.sin theta , cy: cy + r * 0.7 * Math.cos theta , r: r * 0.3 , start: 0 , end: Math.pi * 2 } replace other = other
sayHello :: Process (Task (trace :: Trace)) {} sayHello =
await (traceTask "Hello") (const Halt) main :: Eff (trace :: Trace) {} main = runTask (Process.run (repeatedly sayHello))
· purescript.org · try.purescript.org · purescript.readthedocs.org
More Decks by Brian McKenna
See All by Brian McKenna
Production PureScript
puffnfresh
0
140
Boulder Startup Week: What is functional programming?
puffnfresh
0
76
LambdaConf: Idris Workshop
puffnfresh
2
150
Other Decks in Programming
See All in Programming
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
190
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
270
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
170
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
340
テストだけで見つかる? Rubyでつくるメソッド発掘器
izawa
0
160
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
12k
The Cost of the DOM
ypresto
2
210
エージェントの管理もエージェントに – herdr-core と自作バックログで作る司令塔 –
nearme_tech
PRO
1
120
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
260
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
230
あなたはMCPの機能を、まだ知らない。
4geru
1
740
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
260
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
1.3k
Scaling GitHub
holman
464
140k
Site-Speed That Sticks
csswizardry
13
1.6k
BBQ
matthewcrist
90
10k
Statistics for Hackers
jakevdp
799
230k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
390
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
How to Talk to Developers About Accessibility
jct
2
630
Paper Plane
katiecoart
PRO
6
55k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Un-Boring Meetings
codingconduct
0
510