the power of functional programming and static type ... · 2/18/2017 · the power of functional...
TRANSCRIPT
![Page 1: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/1.jpg)
The Power of Functional
Programming and Static Type
Systems in Server-Side Web
Applications
Oskar Wickström
https://wickstrom.tech
Kats Conf 2, Dublin, Feb 2017
@owickstrom
![Page 3: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/3.jpg)
Me
• I live and work in Malmö, Sweden
• Started out in music
• Found PHP around 2011, then saved by FP soon after
• Worked on the Oden language last year
• Currently building CodeScene at work, mostly in Clojure
• Building Hyper in free time
@owickstrom
![Page 4: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/4.jpg)
Me
• I live and work in Malmö, Sweden
• Started out in music
• Found PHP around 2011, then saved by FP soon after
• Worked on the Oden language last year
• Currently building CodeScene at work, mostly in Clojure
• Building Hyper in free time
@owickstrom
![Page 5: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/5.jpg)
Me
• I live and work in Malmö, Sweden
• Started out in music
• Found PHP around 2011, then saved by FP soon after
• Worked on the Oden language last year
• Currently building CodeScene at work, mostly in Clojure
• Building Hyper in free time
@owickstrom
![Page 6: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/6.jpg)
Me
• I live and work in Malmö, Sweden
• Started out in music
• Found PHP around 2011, then saved by FP soon after
• Worked on the Oden language last year
• Currently building CodeScene at work, mostly in Clojure
• Building Hyper in free time
@owickstrom
![Page 7: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/7.jpg)
Me
• I live and work in Malmö, Sweden
• Started out in music
• Found PHP around 2011, then saved by FP soon after
• Worked on the Oden language last year
• Currently building CodeScene at work, mostly in Clojure
• Building Hyper in free time
@owickstrom
![Page 8: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/8.jpg)
Me
• I live and work in Malmö, Sweden
• Started out in music
• Found PHP around 2011, then saved by FP soon after
• Worked on the Oden language last year
• Currently building CodeScene at work, mostly in Clojure
• Building Hyper in free time
@owickstrom
![Page 9: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/9.jpg)
Me
• I live and work in Malmö, Sweden
• Started out in music
• Found PHP around 2011, then saved by FP soon after
• Worked on the Oden language last year
• Currently building CodeScene at work, mostly in Clojure
• Building Hyper in free time
@owickstrom
![Page 10: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/10.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 11: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/11.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 12: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/12.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 13: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/13.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 14: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/14.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 15: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/15.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 16: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/16.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 17: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/17.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 18: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/18.jpg)
Agenda
• Overview: Functional Programming and Web Applications
• What about Server-Side Rendering?
• Static Typing for Server-Side Web
• Hyper
• Design
• Type-Level Routing
• XHR Clients
• Future Work
@owickstrom
![Page 20: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/20.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 21: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/21.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 22: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/22.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 23: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/23.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 24: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/24.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 25: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/25.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 26: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/26.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 27: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/27.jpg)
Functional Programming Influence
• FP influences Javascript
• ECMAScript 6 has higher-order functions, arrow function syntax
• Libraries like Underscore, Rambda, Fantasy Land
• React is functional at its core
• Functional Reactive Programming (FRP)
• Javascript as a compile target for FP languages
• Still, main focus is single-page apps
@owickstrom
![Page 28: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/28.jpg)
Single-Page Applications
• Work more like desktop applications
• There are a lot of these frameworks in JS
• Angular, Ember, Meteor, React (with friends)
• Without Javascript, you get nothing
• Reinventing the browser
@owickstrom
![Page 29: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/29.jpg)
Single-Page Applications
• Work more like desktop applications
• There are a lot of these frameworks in JS
• Angular, Ember, Meteor, React (with friends)
• Without Javascript, you get nothing
• Reinventing the browser
@owickstrom
![Page 30: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/30.jpg)
Single-Page Applications
• Work more like desktop applications
• There are a lot of these frameworks in JS
• Angular, Ember, Meteor, React (with friends)
• Without Javascript, you get nothing
• Reinventing the browser
@owickstrom
![Page 31: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/31.jpg)
Single-Page Applications
• Work more like desktop applications
• There are a lot of these frameworks in JS
• Angular, Ember, Meteor, React (with friends)
• Without Javascript, you get nothing
• Reinventing the browser
@owickstrom
![Page 32: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/32.jpg)
Single-Page Applications
• Work more like desktop applications
• There are a lot of these frameworks in JS
• Angular, Ember, Meteor, React (with friends)
• Without Javascript, you get nothing
• Reinventing the browser
@owickstrom
![Page 33: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/33.jpg)
Single-Page Applications
• Work more like desktop applications
• There are a lot of these frameworks in JS
• Angular, Ember, Meteor, React (with friends)
• Without Javascript, you get nothing
• Reinventing the browser
@owickstrom
![Page 37: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/37.jpg)
“Isomorphic” Web Applications
• Goal: one framework that runs on both client and server
• “Free progressive enhancements”
• The client and server state machines
• Are we really talking about initial rendering?
@owickstrom
![Page 38: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/38.jpg)
“Isomorphic” Web Applications
• Goal: one framework that runs on both client and server
• “Free progressive enhancements”
• The client and server state machines
• Are we really talking about initial rendering?
@owickstrom
![Page 39: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/39.jpg)
“Isomorphic” Web Applications
• Goal: one framework that runs on both client and server
• “Free progressive enhancements”
• The client and server state machines
• Are we really talking about initial rendering?
@owickstrom
![Page 40: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/40.jpg)
“Isomorphic” Web Applications
• Goal: one framework that runs on both client and server
• “Free progressive enhancements”
• The client and server state machines
• Are we really talking about initial rendering?
@owickstrom
![Page 41: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/41.jpg)
“Isomorphic” Web Applications
• Goal: one framework that runs on both client and server
• “Free progressive enhancements”
• The client and server state machines
• Are we really talking about initial rendering?
@owickstrom
![Page 42: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/42.jpg)
PJAX
• Hooks in on link and form events
• Requests pages over XHR with special header
• Server responds with only inner content
• PJAX swaps the inner content on the client
@owickstrom
![Page 43: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/43.jpg)
PJAX
• Hooks in on link and form events
• Requests pages over XHR with special header
• Server responds with only inner content
• PJAX swaps the inner content on the client
@owickstrom
![Page 44: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/44.jpg)
PJAX
• Hooks in on link and form events
• Requests pages over XHR with special header
• Server responds with only inner content
• PJAX swaps the inner content on the client
@owickstrom
![Page 45: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/45.jpg)
PJAX
• Hooks in on link and form events
• Requests pages over XHR with special header
• Server responds with only inner content
• PJAX swaps the inner content on the client
@owickstrom
![Page 46: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/46.jpg)
PJAX
• Hooks in on link and form events
• Requests pages over XHR with special header
• Server responds with only inner content
• PJAX swaps the inner content on the client
@owickstrom
![Page 47: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/47.jpg)
If server-side web has toolingproblems, let’s build nice tools!
@owickstrom
![Page 49: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/49.jpg)
Static Typing for Server-Side Web
• Mainstream languages in web server programming
• Compile-time guarantees
• Safely abstract and compose
• Maintainable code
• Developer experience
@owickstrom
![Page 50: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/50.jpg)
Static Typing for Server-Side Web
• Mainstream languages in web server programming
• Compile-time guarantees
• Safely abstract and compose
• Maintainable code
• Developer experience
@owickstrom
![Page 51: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/51.jpg)
Static Typing for Server-Side Web
• Mainstream languages in web server programming
• Compile-time guarantees
• Safely abstract and compose
• Maintainable code
• Developer experience
@owickstrom
![Page 52: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/52.jpg)
Static Typing for Server-Side Web
• Mainstream languages in web server programming
• Compile-time guarantees
• Safely abstract and compose
• Maintainable code
• Developer experience
@owickstrom
![Page 53: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/53.jpg)
Static Typing for Server-Side Web
• Mainstream languages in web server programming
• Compile-time guarantees
• Safely abstract and compose
• Maintainable code
• Developer experience
@owickstrom
![Page 54: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/54.jpg)
Static Typing for Server-Side Web
• Mainstream languages in web server programming
• Compile-time guarantees
• Safely abstract and compose
• Maintainable code
• Developer experience
@owickstrom
![Page 55: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/55.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 56: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/56.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 57: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/57.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 58: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/58.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 59: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/59.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 60: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/60.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 61: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/61.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 62: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/62.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 63: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/63.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 64: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/64.jpg)
Things I’ve Found
• Haskell:
• Yesod
• Servant
• Scala:
• Play
• Rho
• PureScript:
• purescript-express
• purescript-rest
@owickstrom
![Page 65: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/65.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 66: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/66.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 67: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/67.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 68: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/68.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 69: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/69.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 70: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/70.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 71: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/71.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 72: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/72.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 73: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/73.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 74: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/74.jpg)
Statically Typed Middleware
• Middleware is a common abstraction
• Very easy to mess up if dynamically typed
• Incorrect ordering
• Corrupt or incomplete responses
• Conflicting writes
• Incorrect error handling
• Consuming non-parsed, or badly parsed, request body
• Missing authentication and/or authorization
• Idea: use extensible records in PureScript!
@owickstrom
![Page 75: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/75.jpg)
![Page 77: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/77.jpg)
Type-safe, statically checked composition of HTTP servers
@owickstrom
![Page 78: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/78.jpg)
Goals
• A safe HTTP middleware architecture
• Make the effects of applying middleware explicit in types
• Ensure correct composition of middleware and application
components
• Interoperability with NodeJS and other backends (purerl,
purescript-native)
• No magic
@owickstrom
![Page 79: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/79.jpg)
Goals
• A safe HTTP middleware architecture
• Make the effects of applying middleware explicit in types
• Ensure correct composition of middleware and application
components
• Interoperability with NodeJS and other backends (purerl,
purescript-native)
• No magic
@owickstrom
![Page 80: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/80.jpg)
Goals
• A safe HTTP middleware architecture
• Make the effects of applying middleware explicit in types
• Ensure correct composition of middleware and application
components
• Interoperability with NodeJS and other backends (purerl,
purescript-native)
• No magic
@owickstrom
![Page 81: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/81.jpg)
Goals
• A safe HTTP middleware architecture
• Make the effects of applying middleware explicit in types
• Ensure correct composition of middleware and application
components
• Interoperability with NodeJS and other backends (purerl,
purescript-native)
• No magic
@owickstrom
![Page 82: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/82.jpg)
Goals
• A safe HTTP middleware architecture
• Make the effects of applying middleware explicit in types
• Ensure correct composition of middleware and application
components
• Interoperability with NodeJS and other backends (purerl,
purescript-native)
• No magic
@owickstrom
![Page 83: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/83.jpg)
Goals
• A safe HTTP middleware architecture
• Make the effects of applying middleware explicit in types
• Ensure correct composition of middleware and application
components
• Interoperability with NodeJS and other backends (purerl,
purescript-native)
• No magic
@owickstrom
![Page 84: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/84.jpg)
How?
• Track middleware effects in type system, pure transformations and
side effects
• Leverage extensible records in PureScript
• Provide a common API for middleware
• Write backend-agnostic middleware where possible
• Integrate with existing NodeJS libraries
@owickstrom
![Page 85: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/85.jpg)
How?
• Track middleware effects in type system, pure transformations and
side effects
• Leverage extensible records in PureScript
• Provide a common API for middleware
• Write backend-agnostic middleware where possible
• Integrate with existing NodeJS libraries
@owickstrom
![Page 86: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/86.jpg)
How?
• Track middleware effects in type system, pure transformations and
side effects
• Leverage extensible records in PureScript
• Provide a common API for middleware
• Write backend-agnostic middleware where possible
• Integrate with existing NodeJS libraries
@owickstrom
![Page 87: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/87.jpg)
How?
• Track middleware effects in type system, pure transformations and
side effects
• Leverage extensible records in PureScript
• Provide a common API for middleware
• Write backend-agnostic middleware where possible
• Integrate with existing NodeJS libraries
@owickstrom
![Page 88: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/88.jpg)
How?
• Track middleware effects in type system, pure transformations and
side effects
• Leverage extensible records in PureScript
• Provide a common API for middleware
• Write backend-agnostic middleware where possible
• Integrate with existing NodeJS libraries
@owickstrom
![Page 89: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/89.jpg)
How?
• Track middleware effects in type system, pure transformations and
side effects
• Leverage extensible records in PureScript
• Provide a common API for middleware
• Write backend-agnostic middleware where possible
• Integrate with existing NodeJS libraries
@owickstrom
![Page 91: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/91.jpg)
Conn
type Conn req res components ={ request :: req, response :: res, components :: components}
@owickstrom
![Page 92: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/92.jpg)
Middleware (Old Design)
type Middleware m c c’ = c -> m c’
@owickstrom
![Page 93: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/93.jpg)
Middleware (Old Design)
authenticateUser >=> parseForm >=> saveTodo
@owickstrom
![Page 94: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/94.jpg)
Whoops, Not Safe
badMiddleware conn = do_ <- respond "First response" connrespond "Second response, crash!" conn
@owickstrom
![Page 95: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/95.jpg)
Middleware (Revised)
newtype Middleware m i o a =Middleware (i -> m (Tuple a o))
@owickstrom
![Page 96: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/96.jpg)
Response State Transitions
• Hyper tracks the state of response writing
• Guarantees correctness in response side effects
• Abstractions can be built on top safely
• Response-writing middleware can be backend-agnostic
@owickstrom
![Page 97: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/97.jpg)
Response State Transitions
• Hyper tracks the state of response writing
• Guarantees correctness in response side effects
• Abstractions can be built on top safely
• Response-writing middleware can be backend-agnostic
@owickstrom
![Page 98: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/98.jpg)
Response State Transitions
• Hyper tracks the state of response writing
• Guarantees correctness in response side effects
• Abstractions can be built on top safely
• Response-writing middleware can be backend-agnostic
@owickstrom
![Page 99: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/99.jpg)
Response State Transitions
• Hyper tracks the state of response writing
• Guarantees correctness in response side effects
• Abstractions can be built on top safely
• Response-writing middleware can be backend-agnostic
@owickstrom
![Page 100: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/100.jpg)
Response State Transitions
• Hyper tracks the state of response writing
• Guarantees correctness in response side effects
• Abstractions can be built on top safely
• Response-writing middleware can be backend-agnostic
@owickstrom
![Page 101: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/101.jpg)
ResponseStateTransition
type ResponseStateTransition m rw from to =
forall req res c.Middlewarem(Conn req {writer :: rw from | res} c)(Conn req {writer :: rw to | res} c)Unit
@owickstrom
![Page 102: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/102.jpg)
ResponseStateTransition
type ResponseStateTransition m rw from to =forall req res c.
Middlewarem(Conn req {writer :: rw from | res} c)(Conn req {writer :: rw to | res} c)Unit
@owickstrom
![Page 103: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/103.jpg)
ResponseStateTransition
type ResponseStateTransition m rw from to =forall req res c.Middlewarem
(Conn req {writer :: rw from | res} c)(Conn req {writer :: rw to | res} c)Unit
@owickstrom
![Page 104: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/104.jpg)
ResponseStateTransition
type ResponseStateTransition m rw from to =forall req res c.Middlewarem(Conn req {writer :: rw from | res} c)
(Conn req {writer :: rw to | res} c)Unit
@owickstrom
![Page 105: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/105.jpg)
ResponseStateTransition
type ResponseStateTransition m rw from to =forall req res c.Middlewarem(Conn req {writer :: rw from | res} c)(Conn req {writer :: rw to | res} c)
Unit
@owickstrom
![Page 106: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/106.jpg)
ResponseStateTransition
type ResponseStateTransition m rw from to =forall req res c.Middlewarem(Conn req {writer :: rw from | res} c)(Conn req {writer :: rw to | res} c)Unit
@owickstrom
![Page 107: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/107.jpg)
ResponseWriterclass ResponseWriter rw m b | rw -> b where
writeStatus:: Status-> ResponseStateTransition m rw StatusLineOpen HeadersOpen
writeHeader:: Header-> ResponseStateTransition m rw HeadersOpen HeadersOpen
closeHeaders:: ResponseStateTransition m rw HeadersOpen BodyOpen
send:: b-> ResponseStateTransition m rw BodyOpen BodyOpen
end:: ResponseStateTransition m rw BodyOpen ResponseEnded
@owickstrom
![Page 108: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/108.jpg)
ResponseWriterclass ResponseWriter rw m b | rw -> b wherewriteStatus:: Status-> ResponseStateTransition m rw StatusLineOpen HeadersOpen
writeHeader:: Header-> ResponseStateTransition m rw HeadersOpen HeadersOpen
closeHeaders:: ResponseStateTransition m rw HeadersOpen BodyOpen
send:: b-> ResponseStateTransition m rw BodyOpen BodyOpen
end:: ResponseStateTransition m rw BodyOpen ResponseEnded
@owickstrom
![Page 109: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/109.jpg)
ResponseWriterclass ResponseWriter rw m b | rw -> b wherewriteStatus:: Status-> ResponseStateTransition m rw StatusLineOpen HeadersOpen
writeHeader:: Header-> ResponseStateTransition m rw HeadersOpen HeadersOpen
closeHeaders:: ResponseStateTransition m rw HeadersOpen BodyOpen
send:: b-> ResponseStateTransition m rw BodyOpen BodyOpen
end:: ResponseStateTransition m rw BodyOpen ResponseEnded
@owickstrom
![Page 110: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/110.jpg)
ResponseWriterclass ResponseWriter rw m b | rw -> b wherewriteStatus:: Status-> ResponseStateTransition m rw StatusLineOpen HeadersOpen
writeHeader:: Header-> ResponseStateTransition m rw HeadersOpen HeadersOpen
closeHeaders:: ResponseStateTransition m rw HeadersOpen BodyOpen
send:: b-> ResponseStateTransition m rw BodyOpen BodyOpen
end:: ResponseStateTransition m rw BodyOpen ResponseEnded
@owickstrom
![Page 111: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/111.jpg)
ResponseWriterclass ResponseWriter rw m b | rw -> b wherewriteStatus:: Status-> ResponseStateTransition m rw StatusLineOpen HeadersOpen
writeHeader:: Header-> ResponseStateTransition m rw HeadersOpen HeadersOpen
closeHeaders:: ResponseStateTransition m rw HeadersOpen BodyOpen
send:: b-> ResponseStateTransition m rw BodyOpen BodyOpen
end:: ResponseStateTransition m rw BodyOpen ResponseEnded
@owickstrom
![Page 112: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/112.jpg)
ResponseWriterclass ResponseWriter rw m b | rw -> b wherewriteStatus:: Status-> ResponseStateTransition m rw StatusLineOpen HeadersOpen
writeHeader:: Header-> ResponseStateTransition m rw HeadersOpen HeadersOpen
closeHeaders:: ResponseStateTransition m rw HeadersOpen BodyOpen
send:: b-> ResponseStateTransition m rw BodyOpen BodyOpen
end:: ResponseStateTransition m rw BodyOpen ResponseEnded
@owickstrom
![Page 113: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/113.jpg)
What if we do it wrong?
v20 writeStatus statusOK21 :*> respond "Hello, Hyper!"22 :*> closeHeaders
^
Could not match type
BodyOpen
with type
HeadersOpen
@owickstrom
![Page 114: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/114.jpg)
Writing Headers
headers
:: forall t m req res rw b c.(Traversable t, Monad m, ResponseWriter rw m b) =>t Header
-> Middlewarem(Conn req { writer :: rw HeadersOpen | res } c)(Conn req { writer :: rw BodyOpen | res } c)Unit
headers hs =traverse_ writeHeader hs:*> closeHeaders
@owickstrom
![Page 115: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/115.jpg)
Writing Headers
headers:: forall t m req res rw b c.
(Traversable t, Monad m, ResponseWriter rw m b) =>t Header
-> Middlewarem(Conn req { writer :: rw HeadersOpen | res } c)(Conn req { writer :: rw BodyOpen | res } c)Unit
headers hs =traverse_ writeHeader hs:*> closeHeaders
@owickstrom
![Page 116: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/116.jpg)
Writing Headers
headers:: forall t m req res rw b c.
(Traversable t, Monad m, ResponseWriter rw m b) =>t Header
-> Middlewarem(Conn req { writer :: rw HeadersOpen | res } c)(Conn req { writer :: rw BodyOpen | res } c)Unit
headers hs =traverse_ writeHeader hs:*> closeHeaders
@owickstrom
![Page 117: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/117.jpg)
Writing Headers
headers:: forall t m req res rw b c.
(Traversable t, Monad m, ResponseWriter rw m b) =>t Header
-> Middlewarem(Conn req { writer :: rw HeadersOpen | res } c)(Conn req { writer :: rw BodyOpen | res } c)Unit
headers hs =traverse_ writeHeader hs:*> closeHeaders
@owickstrom
![Page 119: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/119.jpg)
A Routing Type
data Home = Home
type Site1 = Get HTML Home
@owickstrom
![Page 120: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/120.jpg)
Handler
home :: forall m. Monad m=> ExceptT RoutingError m Home
home = pure Home
@owickstrom
![Page 121: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/121.jpg)
HTMLEncode
instance encodeHTMLHome :: EncodeHTML Home whereencodeHTML Home =p [] [ text "Welcome to my site!" ]
@owickstrom
![Page 122: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/122.jpg)
Proxy
The Proxy type and values are for situations where type information is
required for an input to determine the type of an output, but where it is
not possible or convenient to provide a value for the input.
@owickstrom
![Page 124: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/124.jpg)
Site Router
onRoutingError status msg =writeStatus status:*> contentType textHTML:*> closeHeaders:*> respond (maybe "" id msg)
site1Router = router site1 home onRoutingError
@owickstrom
![Page 125: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/125.jpg)
Main Entrypoint
main =runServer defaultOptions
onListeningonRequestError{}site1Router
whereonListening (Port port) =
log ("Listening on http://localhost:" <> show port)
onRequestError err =log ("Request failed: " <> show err)
@owickstrom
![Page 127: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/127.jpg)
Multiple Endpoints with Captures
data Home = Home
data AllUsers = AllUsers (Array User)
newtype User = User { id :: Int, name :: String }
type Site2 =Get HTML Home:<|> "users" :/ Get HTML AllUsers:<|> "users" :/ Capture "user-id" Int :> Get HTML User
@owickstrom
![Page 128: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/128.jpg)
Multiple Handlers
home :: forall m. Monad m => ExceptT RoutingError m Homehome = pure Home
allUsers :: forall m. Monad m => ExceptT RoutingError m AllUsersallUsers = AllUsers <$> getUsers
getUser :: forall m. Monad m => Int -> ExceptT RoutingError m UsergetUser id’ =
find userWithId <$> getUsers >>=case _ of
Just user -> pure userNothing ->
throwError (HTTPError { status: statusNotFound, message: Just "User not found."})
whereuserWithId (User u) = u.id == id’
@owickstrom
![Page 129: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/129.jpg)
Multiple Handlers
home :: forall m. Monad m => ExceptT RoutingError m Homehome = pure Home
allUsers :: forall m. Monad m => ExceptT RoutingError m AllUsersallUsers = AllUsers <$> getUsers
getUser :: forall m. Monad m => Int -> ExceptT RoutingError m UsergetUser id’ =
find userWithId <$> getUsers >>=case _ of
Just user -> pure userNothing ->
throwError (HTTPError { status: statusNotFound, message: Just "User not found."})
whereuserWithId (User u) = u.id == id’
@owickstrom
![Page 130: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/130.jpg)
Multiple Handlers
home :: forall m. Monad m => ExceptT RoutingError m Homehome = pure Home
allUsers :: forall m. Monad m => ExceptT RoutingError m AllUsersallUsers = AllUsers <$> getUsers
getUser :: forall m. Monad m => Int -> ExceptT RoutingError m UsergetUser id’ =find userWithId <$> getUsers >>=case _ ofJust user -> pure userNothing ->
throwError (HTTPError { status: statusNotFound, message: Just "User not found."})
whereuserWithId (User u) = u.id == id’
@owickstrom
![Page 131: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/131.jpg)
Type-Safe Links
instance encodeHTMLAllUsers :: EncodeHTML AllUsers whereencodeHTML (AllUsers users) =
element_ "div" [ h1 [] [ text "Users" ], ul [] (map linkToUser users)]
wherelinkToUser (User u) =case linksTo site2 of_ :<|> _ :<|> getUser’ ->li [] [ linkTo (getUser’ u.id) [ text u.name ] ]
@owickstrom
![Page 132: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/132.jpg)
Type-Safe Links
instance encodeHTMLAllUsers :: EncodeHTML AllUsers whereencodeHTML (AllUsers users) =element_ "div" [ h1 [] [ text "Users" ]
, ul [] (map linkToUser users)]
wherelinkToUser (User u) =case linksTo site2 of_ :<|> _ :<|> getUser’ ->li [] [ linkTo (getUser’ u.id) [ text u.name ] ]
@owickstrom
![Page 133: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/133.jpg)
Type-Safe Links
instance encodeHTMLAllUsers :: EncodeHTML AllUsers whereencodeHTML (AllUsers users) =element_ "div" [ h1 [] [ text "Users" ]
, ul [] (map linkToUser users)]
wherelinkToUser (User u) =case linksTo site2 of_ :<|> _ :<|> getUser’ ->
li [] [ linkTo (getUser’ u.id) [ text u.name ] ]
@owickstrom
![Page 134: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/134.jpg)
Multiple Endpoint Router
site2Router =router site2 (home :<|> allUsers :<|> getUser) onRoutingError
@owickstrom
![Page 136: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/136.jpg)
Shared Routing Type
type TaskId = Int
data Task = Task TaskId String
@owickstrom
![Page 137: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/137.jpg)
Shared Routing Type
derive instance genericTask :: Generic Task
instance showTask :: Show Task whereshow = gShow
instance encodeJsonTask :: EncodeJson Task whereencodeJson = gEncodeJson
instance decodeJsonTask :: DecodeJson Task wheredecodeJson = gDecodeJson
@owickstrom
![Page 138: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/138.jpg)
Shared Routing Type
type Site ="tasks" :/ (Get Json (Array Task)
:<|> Capture "id" TaskId :> Get Json Task)
site :: Proxy Sitesite = Proxy
@owickstrom
![Page 139: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/139.jpg)
Shared Routing Type
type Site ="tasks" :/ (Get Json (Array Task)
:<|> Capture "id" TaskId :> Get Json Task)
site :: Proxy Sitesite = Proxy
@owickstrom
![Page 140: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/140.jpg)
Shared Routing Type
update :: Action-> State-> EffModel State Action (ajax :: AJAX)
update RequestTasks state =case asClients site of
allTasks :<|> _ ->{ state: state { status = "Fetching tasks..." }, effects: [ ReceiveTasks <$> allTasks ]}
@owickstrom
![Page 141: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/141.jpg)
Shared Routing Type
update :: Action-> State-> EffModel State Action (ajax :: AJAX)
update RequestTasks state =case asClients site ofallTasks :<|> _ ->
{ state: state { status = "Fetching tasks..." }, effects: [ ReceiveTasks <$> allTasks ]}
@owickstrom
![Page 142: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/142.jpg)
Shared Routing Type
update :: Action-> State-> EffModel State Action (ajax :: AJAX)
update RequestTasks state =case asClients site ofallTasks :<|> _ ->{ state: state { status = "Fetching tasks..." }, effects: [ ReceiveTasks <$> allTasks ]}
@owickstrom
![Page 143: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/143.jpg)
Other Possibilites/Future Work
• Type-safe forms
• PJAX, but with JSON data and client-side templates
• Mocked servers and clients using Arbitrary instances
• Ring-like response map abstraction
• Other backends
• Continue to Quest For Type-Safe Web!
@owickstrom
![Page 144: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/144.jpg)
Other Possibilites/Future Work
• Type-safe forms
• PJAX, but with JSON data and client-side templates
• Mocked servers and clients using Arbitrary instances
• Ring-like response map abstraction
• Other backends
• Continue to Quest For Type-Safe Web!
@owickstrom
![Page 145: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/145.jpg)
Other Possibilites/Future Work
• Type-safe forms
• PJAX, but with JSON data and client-side templates
• Mocked servers and clients using Arbitrary instances
• Ring-like response map abstraction
• Other backends
• Continue to Quest For Type-Safe Web!
@owickstrom
![Page 146: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/146.jpg)
Other Possibilites/Future Work
• Type-safe forms
• PJAX, but with JSON data and client-side templates
• Mocked servers and clients using Arbitrary instances
• Ring-like response map abstraction
• Other backends
• Continue to Quest For Type-Safe Web!
@owickstrom
![Page 147: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/147.jpg)
Other Possibilites/Future Work
• Type-safe forms
• PJAX, but with JSON data and client-side templates
• Mocked servers and clients using Arbitrary instances
• Ring-like response map abstraction
• Other backends
• Continue to Quest For Type-Safe Web!
@owickstrom
![Page 148: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/148.jpg)
Other Possibilites/Future Work
• Type-safe forms
• PJAX, but with JSON data and client-side templates
• Mocked servers and clients using Arbitrary instances
• Ring-like response map abstraction
• Other backends
• Continue to Quest For Type-Safe Web!
@owickstrom
![Page 149: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/149.jpg)
Other Possibilites/Future Work
• Type-safe forms
• PJAX, but with JSON data and client-side templates
• Mocked servers and clients using Arbitrary instances
• Ring-like response map abstraction
• Other backends
• Continue to Quest For Type-Safe Web!
@owickstrom
![Page 152: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/152.jpg)
Useful References I
I Gustaf Nilsson Kotte. 6 Reasons Isomorphic Web Apps is not the
Silver Bullet You’re Looking For. url:
https://blog.jayway.com/2016/05/23/6-reasons-isomorphic-web-apps-not-
silver-bullet-youre-looking/.
I PJAX = pushState + ajax. url: https://github.com/defunkt/jquery-pjax.
I Yesod: Web Framework for Haskell. url: http://www.yesodweb.com/.
I Servant: A Type-Level Web DSL. url: https://haskell-servant.github.io/.
@owickstrom
![Page 153: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/153.jpg)
Useful References II
I Play: The High Velocity Web Framework For Java and Scala. url:
https://www.playframework.com/.
I Rho: A DSL for building HTTP services with http4s. url:
https://github.com/http4s/rho.
I purescript-express: Purescript wrapper around Node.js Express
web-framework. url:
https://github.com/dancingrobot84/purescript-express.
I purescript-rest: A toolkit for creating REST services with Node and
PureScript. url: https://github.com/dicomgrid/purescript-rest.
@owickstrom
![Page 154: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/154.jpg)
Useful References III
I Hyper: Type-safe, statically checked composition of HTTP servers.
url: https://owickstrom.github.io/hyper/.
I purescript-proxy: Value proxy for type inputs. url:
https://pursuit.purescript.org/packages/purescript-proxy/1.0.0.
I Ring: Clojure HTTP server abstraction. url:
https://github.com/ring-clojure.
I Automatically derived XHR clients for Hyper routing types. url:
https://github.com/owickstrom/purescript-hyper-routing-xhr.
@owickstrom
![Page 155: The Power of Functional Programming and Static Type ... · 2/18/2017 · The Power of Functional Programming and Static Type Systems in Server-Side Web Applications Oskar Wickström](https://reader034.vdocuments.site/reader034/viewer/2022050306/5f6f0a2da255d11aa03e538f/html5/thumbnails/155.jpg)
The Power of Functional
Programming and Static Type
Systems in Server-Side Web
Applications
Oskar Wickström
https://wickstrom.tech
Kats Conf 2, Dublin, Feb 2017
@owickstrom