SlideShare a Scribd company logo
lounge / Kraków / 16.02.2016
FUNCTIONAL
WEB APPS
Michał Płachta
@miciek
PURELY
SUCH
PURE
lounge / Kraków / 16.02.2016@miciek
Let’s create a full-blown
web application
lounge / Kraków / 16.02.2016@miciek
MAIN DEV GOALS
■ explicit external dependencies
■ explicit side effects
■ explicit configuration
■ explicit error handling
pure functions & strong typesSolution:
lounge / Kraków / 16.02.2016@miciek
Gitlab
lounge / Kraków / 16.02.2016@miciek
Merge Request Stats
Gitlab Our app
lounge / Kraków / 16.02.2016@miciek
Application Architecture
Gitlab Server
Merge Request
Fetcher
MR Stats
Web Service
In Memory
Storage
MR Stats
Web Application
data flow
lounge / Kraków / 16.02.2016@miciek
Haskell & Elm
Gitlab Server
Merge Request
Fetcher
MR Stats
Web Service
In Memory
Storage
MR Stats
Web Application
data flow
Elm
lounge / Kraków / 16.02.2016@miciek
One slide Haskell tutorial
lounge / Kraków / 16.02.2016@miciek
Using Servant as
HTTP Client
lounge / Kraków / 16.02.2016@miciek
Haskell Servant
■ set of libraries
■ for HTTP related stuff
■ DRY
■ type safe
■ type level DSL
lounge / Kraków / 16.02.2016@miciek
Let’s start with the Fetcher
Gitlab Server
Merge Request
Fetcher
MR Stats
Web Service
In Memory
Storage
MR Stats
Web Application
data flow
lounge / Kraków / 16.02.2016@miciek
Gitlab API
lounge / Kraków / 16.02.2016@miciek
Merge Request JSON
lounge / Kraków / 16.02.2016@miciek
Merge Request Data Type
lounge / Kraków / 16.02.2016@miciek
API Type
/api/v3/projects/{projectId}/merge_requests/?page={page}
lounge / Kraków / 16.02.2016@miciek
apiQuery Function Type
URL to query
lounge / Kraków / 16.02.2016@miciek
queryApi Return Type
EitherT
ServantError
IO
Paged
[MergeRequest]
lounge / Kraków / 16.02.2016@miciek
IO Type
IO
Paged
[MergeRequest]
■ side effecting
■ an action
■ e.g. get something
from the server
■ can’t get rid of it
lounge / Kraków / 16.02.2016@miciek
Quick IO Side Note
What’s the difference?
Examples from Haskell
lounge / Kraków / 16.02.2016@miciek
EitherT
EitherT
ServantError IO
■ can be either Left or Right
■ Left contains ServantError
■ Right contains IO a
lounge / Kraków / 16.02.2016@miciek
ServantError
■ FailureResponse
■ DecodeFailure
■ UnsupportedContentType
■ ConnectionError
■ InvalidContentTypeHeader
lounge / Kraków / 16.02.2016@miciek
apiQuery implementation
client is a Servant
function that looks at
our type and provides
the implementation
lounge / Kraków / 16.02.2016@miciek
Nicer API with AppConfig
lounge / Kraków / 16.02.2016@miciek
pagedMergeRequests function
■ Maybe a type can be
○ Just a
○ Nothing
lounge / Kraków / 16.02.2016@miciek
allMergeRequests function
uses
lounge / Kraków / 16.02.2016@miciek
allMergeRequests implementation
lounge / Kraków / 16.02.2016@miciek
Side Note: Side Effects without IO?
lounge / Kraków / 16.02.2016@miciek
Merge Request Fetcher module
lounge / Kraków / 16.02.2016@miciek
Same story: Comments
lounge / Kraków / 16.02.2016@miciek
Business Logic: Stats Calculations
■ title
■ create date
■ last update date
■ upvotes
■ downvotes
■ list of comments
■ Merge Request object
■ time to merge (calculated)
■ comments quantity (calculated)
■ url to the MR
Merge Request (from Gitlab) Merge Request Stats (ours)
lounge / Kraków / 16.02.2016@miciek
calculateStats function
no IO!
lounge / Kraków / 16.02.2016@miciek
Now onto: In Memory Storage
Gitlab Server
Merge Request
Fetcher
MR Stats
Web Service
In Memory
Storage
MR Stats
Web Application
data flow
lounge / Kraków / 16.02.2016@miciek
StatsStorage
lounge / Kraków / 16.02.2016@miciek
main function
lounge / Kraków / 16.02.2016@miciek
fetchMRsAndSaveStats function
lounge / Kraków / 16.02.2016@miciek
Serving the stats
lounge / Kraków / 16.02.2016@miciek
We did it!
Merge Request
Fetcher
MR Stats
Web Service
In Memory
Storage
lounge / Kraków / 16.02.2016@miciek
Automatic JS client and Markdown!
lounge / Kraków / 16.02.2016@miciek
Let’s do the frontend
data flow
Gitlab Server
Merge Request
Fetcher
MR Stats
Web Service
In Memory
Storage
MR Stats
Web Application
■ using Elm
■ merge request stats in a table
■ dynamically updated each 5 seconds
lounge / Kraków / 16.02.2016@miciek
Elm architecture
Elm Runtime
Model
update
Action
New
Model
view
Effect
Html
Object
Elm Rendering
lounge / Kraków / 16.02.2016@miciek
Elm architecture in types
lounge / Kraków / 16.02.2016@miciek
Our Model
lounge / Kraków / 16.02.2016@miciek
Our Actions
■ UpdateList is generated inside the app
■ Tick is generated outside of the app
lounge / Kraków / 16.02.2016@miciek
update Function
lounge / Kraków / 16.02.2016@miciek
mergeRequestsFetchEffect
lounge / Kraków / 16.02.2016@miciek
view = virtual DOM objects
lounge / Kraków / 16.02.2016@miciek
Effects are Data
Elm Runtime
MRs &
refresh
time
update
Tick or
Update
List
Action
MRs &
refresh
time
view
Tick or
Fetch
Effect
MRs
Table
Object
Elm Rendering
lounge / Kraków / 16.02.2016@miciek
DEMO TIME!
Fame & Glory
lounge / Kraków / 16.02.2016@miciek
Time Travel Debugger
See for yourself: http://debug.elm-lang.org/edit/Mario.elm
lounge / Kraków / 16.02.2016@miciek
Links
■ Backend project: https://github.com/miciek/mr-stats-haskell-
servant
■ Frontend project: https://github.com/miciek/mr-stats-frontend-
elm
■ Elm architecture tutorial: https://github.com/evancz/elm-
architecture-tutorial
■ Haskell Servant: https://github.com/haskell-servant/servant
■ Let’s be mainstream - user-focused design in Elm: https://www.
youtube.com/watch?v=oYk8CKH7OhE
■ Monad Transformers: https://www.youtube.com/watch?
v=pzouxmWiemg
■ Make the backend team jealous - Elm in Production: https://www.
youtube.com/watch?v=FV0DXNB94NE
■ Children do projects using Elm: http://outreach.mcmaster.
ca/tutorials/shapes/shapes.html
lounge / Kraków / 16.02.2016
PURELY FUNCTIONAL
WEB APPS
Michał Płachta
www.michalplachta.com
@miciek
THANK YOU!

More Related Content

Similar to Purely Functional Web Apps (Extended Version, 16.02.2016)

Angular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entrepriseAngular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entreprise
LINAGORA
 
The Javascript Ecosystem
The Javascript EcosystemThe Javascript Ecosystem
The Javascript Ecosystem
Emmanuel Akinde
 
Front end microservices: architectures and solution
Front end microservices: architectures and solutionFront end microservices: architectures and solution
Front end microservices: architectures and solution
Mikhail Kuznetcov
 
Angular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - LinagoraAngular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - Linagora
LINAGORA
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017
Melania Andrisan (Danciu)
 
Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...
Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...
Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...
HostedbyConfluent
 
A Laugh RIAt -- OWASP 2009 Web 2.0 Talk
A Laugh RIAt -- OWASP 2009 Web 2.0 TalkA Laugh RIAt -- OWASP 2009 Web 2.0 Talk
A Laugh RIAt -- OWASP 2009 Web 2.0 Talk
Rafal Los
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!
Jonas Bandi
 
2020 [pweb] 13 typescript
2020 [pweb] 13 typescript2020 [pweb] 13 typescript
2020 [pweb] 13 typescript
VICTOR JATOBÁ
 
Why reinvent the wheel at Criteo?
Why reinvent the wheel at Criteo? Why reinvent the wheel at Criteo?
Why reinvent the wheel at Criteo?
Criteolabs
 
Apache Sling as a Microservices Gateway
Apache Sling as a Microservices GatewayApache Sling as a Microservices Gateway
Apache Sling as a Microservices Gateway
Robert Munteanu
 
Building a Browser for Automotive: Alternatives, Challenges and Recommendations
Building a Browser for Automotive: Alternatives, Challenges and RecommendationsBuilding a Browser for Automotive: Alternatives, Challenges and Recommendations
Building a Browser for Automotive: Alternatives, Challenges and Recommendations
juanjosanchezpenas
 
Building a browser for automotive. alternatives, challenges and recommendatio...
Building a browser for automotive. alternatives, challenges and recommendatio...Building a browser for automotive. alternatives, challenges and recommendatio...
Building a browser for automotive. alternatives, challenges and recommendatio...
Igalia
 
Building Cool Applications with WSO2 StratosLive
Building Cool Applications with WSO2 StratosLiveBuilding Cool Applications with WSO2 StratosLive
Building Cool Applications with WSO2 StratosLiveWSO2
 
Boost your productivity for free!
Boost your productivity for free!Boost your productivity for free!
Boost your productivity for free!Maciej Majchrzak
 
Angular intro
Angular introAngular intro
Angular intro
Janarthan Paramanandam
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
Gobinda Karmakar ☁
 
Micro Services and LaSalle Software
Micro Services and LaSalle SoftwareMicro Services and LaSalle Software
Micro Services and LaSalle Software
Bob Bloom
 
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
Codemotion
 

Similar to Purely Functional Web Apps (Extended Version, 16.02.2016) (20)

APIs for mobile
APIs for mobileAPIs for mobile
APIs for mobile
 
Angular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entrepriseAngular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entreprise
 
The Javascript Ecosystem
The Javascript EcosystemThe Javascript Ecosystem
The Javascript Ecosystem
 
Front end microservices: architectures and solution
Front end microservices: architectures and solutionFront end microservices: architectures and solution
Front end microservices: architectures and solution
 
Angular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - LinagoraAngular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - Linagora
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017
 
Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...
Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...
Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svo...
 
A Laugh RIAt -- OWASP 2009 Web 2.0 Talk
A Laugh RIAt -- OWASP 2009 Web 2.0 TalkA Laugh RIAt -- OWASP 2009 Web 2.0 Talk
A Laugh RIAt -- OWASP 2009 Web 2.0 Talk
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!
 
2020 [pweb] 13 typescript
2020 [pweb] 13 typescript2020 [pweb] 13 typescript
2020 [pweb] 13 typescript
 
Why reinvent the wheel at Criteo?
Why reinvent the wheel at Criteo? Why reinvent the wheel at Criteo?
Why reinvent the wheel at Criteo?
 
Apache Sling as a Microservices Gateway
Apache Sling as a Microservices GatewayApache Sling as a Microservices Gateway
Apache Sling as a Microservices Gateway
 
Building a Browser for Automotive: Alternatives, Challenges and Recommendations
Building a Browser for Automotive: Alternatives, Challenges and RecommendationsBuilding a Browser for Automotive: Alternatives, Challenges and Recommendations
Building a Browser for Automotive: Alternatives, Challenges and Recommendations
 
Building a browser for automotive. alternatives, challenges and recommendatio...
Building a browser for automotive. alternatives, challenges and recommendatio...Building a browser for automotive. alternatives, challenges and recommendatio...
Building a browser for automotive. alternatives, challenges and recommendatio...
 
Building Cool Applications with WSO2 StratosLive
Building Cool Applications with WSO2 StratosLiveBuilding Cool Applications with WSO2 StratosLive
Building Cool Applications with WSO2 StratosLive
 
Boost your productivity for free!
Boost your productivity for free!Boost your productivity for free!
Boost your productivity for free!
 
Angular intro
Angular introAngular intro
Angular intro
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
Micro Services and LaSalle Software
Micro Services and LaSalle SoftwareMicro Services and LaSalle Software
Micro Services and LaSalle Software
 
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
 

Recently uploaded

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 

Recently uploaded (20)

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 

Purely Functional Web Apps (Extended Version, 16.02.2016)

  • 1. lounge / Kraków / 16.02.2016 FUNCTIONAL WEB APPS Michał Płachta @miciek PURELY SUCH PURE
  • 2. lounge / Kraków / 16.02.2016@miciek Let’s create a full-blown web application
  • 3. lounge / Kraków / 16.02.2016@miciek MAIN DEV GOALS ■ explicit external dependencies ■ explicit side effects ■ explicit configuration ■ explicit error handling pure functions & strong typesSolution:
  • 4. lounge / Kraków / 16.02.2016@miciek Gitlab
  • 5. lounge / Kraków / 16.02.2016@miciek Merge Request Stats Gitlab Our app
  • 6. lounge / Kraków / 16.02.2016@miciek Application Architecture Gitlab Server Merge Request Fetcher MR Stats Web Service In Memory Storage MR Stats Web Application data flow
  • 7. lounge / Kraków / 16.02.2016@miciek Haskell & Elm Gitlab Server Merge Request Fetcher MR Stats Web Service In Memory Storage MR Stats Web Application data flow Elm
  • 8. lounge / Kraków / 16.02.2016@miciek One slide Haskell tutorial
  • 9. lounge / Kraków / 16.02.2016@miciek Using Servant as HTTP Client
  • 10. lounge / Kraków / 16.02.2016@miciek Haskell Servant ■ set of libraries ■ for HTTP related stuff ■ DRY ■ type safe ■ type level DSL
  • 11. lounge / Kraków / 16.02.2016@miciek Let’s start with the Fetcher Gitlab Server Merge Request Fetcher MR Stats Web Service In Memory Storage MR Stats Web Application data flow
  • 12. lounge / Kraków / 16.02.2016@miciek Gitlab API
  • 13. lounge / Kraków / 16.02.2016@miciek Merge Request JSON
  • 14. lounge / Kraków / 16.02.2016@miciek Merge Request Data Type
  • 15. lounge / Kraków / 16.02.2016@miciek API Type /api/v3/projects/{projectId}/merge_requests/?page={page}
  • 16. lounge / Kraków / 16.02.2016@miciek apiQuery Function Type URL to query
  • 17. lounge / Kraków / 16.02.2016@miciek queryApi Return Type EitherT ServantError IO Paged [MergeRequest]
  • 18. lounge / Kraków / 16.02.2016@miciek IO Type IO Paged [MergeRequest] ■ side effecting ■ an action ■ e.g. get something from the server ■ can’t get rid of it
  • 19. lounge / Kraków / 16.02.2016@miciek Quick IO Side Note What’s the difference? Examples from Haskell
  • 20. lounge / Kraków / 16.02.2016@miciek EitherT EitherT ServantError IO ■ can be either Left or Right ■ Left contains ServantError ■ Right contains IO a
  • 21. lounge / Kraków / 16.02.2016@miciek ServantError ■ FailureResponse ■ DecodeFailure ■ UnsupportedContentType ■ ConnectionError ■ InvalidContentTypeHeader
  • 22. lounge / Kraków / 16.02.2016@miciek apiQuery implementation client is a Servant function that looks at our type and provides the implementation
  • 23. lounge / Kraków / 16.02.2016@miciek Nicer API with AppConfig
  • 24. lounge / Kraków / 16.02.2016@miciek pagedMergeRequests function ■ Maybe a type can be ○ Just a ○ Nothing
  • 25. lounge / Kraków / 16.02.2016@miciek allMergeRequests function uses
  • 26. lounge / Kraków / 16.02.2016@miciek allMergeRequests implementation
  • 27. lounge / Kraków / 16.02.2016@miciek Side Note: Side Effects without IO?
  • 28. lounge / Kraków / 16.02.2016@miciek Merge Request Fetcher module
  • 29. lounge / Kraków / 16.02.2016@miciek Same story: Comments
  • 30. lounge / Kraków / 16.02.2016@miciek Business Logic: Stats Calculations ■ title ■ create date ■ last update date ■ upvotes ■ downvotes ■ list of comments ■ Merge Request object ■ time to merge (calculated) ■ comments quantity (calculated) ■ url to the MR Merge Request (from Gitlab) Merge Request Stats (ours)
  • 31. lounge / Kraków / 16.02.2016@miciek calculateStats function no IO!
  • 32. lounge / Kraków / 16.02.2016@miciek Now onto: In Memory Storage Gitlab Server Merge Request Fetcher MR Stats Web Service In Memory Storage MR Stats Web Application data flow
  • 33. lounge / Kraków / 16.02.2016@miciek StatsStorage
  • 34. lounge / Kraków / 16.02.2016@miciek main function
  • 35. lounge / Kraków / 16.02.2016@miciek fetchMRsAndSaveStats function
  • 36. lounge / Kraków / 16.02.2016@miciek Serving the stats
  • 37. lounge / Kraków / 16.02.2016@miciek We did it! Merge Request Fetcher MR Stats Web Service In Memory Storage
  • 38. lounge / Kraków / 16.02.2016@miciek Automatic JS client and Markdown!
  • 39. lounge / Kraków / 16.02.2016@miciek Let’s do the frontend data flow Gitlab Server Merge Request Fetcher MR Stats Web Service In Memory Storage MR Stats Web Application ■ using Elm ■ merge request stats in a table ■ dynamically updated each 5 seconds
  • 40. lounge / Kraków / 16.02.2016@miciek Elm architecture Elm Runtime Model update Action New Model view Effect Html Object Elm Rendering
  • 41. lounge / Kraków / 16.02.2016@miciek Elm architecture in types
  • 42. lounge / Kraków / 16.02.2016@miciek Our Model
  • 43. lounge / Kraków / 16.02.2016@miciek Our Actions ■ UpdateList is generated inside the app ■ Tick is generated outside of the app
  • 44. lounge / Kraków / 16.02.2016@miciek update Function
  • 45. lounge / Kraków / 16.02.2016@miciek mergeRequestsFetchEffect
  • 46. lounge / Kraków / 16.02.2016@miciek view = virtual DOM objects
  • 47. lounge / Kraków / 16.02.2016@miciek Effects are Data Elm Runtime MRs & refresh time update Tick or Update List Action MRs & refresh time view Tick or Fetch Effect MRs Table Object Elm Rendering
  • 48. lounge / Kraków / 16.02.2016@miciek DEMO TIME! Fame & Glory
  • 49. lounge / Kraków / 16.02.2016@miciek Time Travel Debugger See for yourself: http://debug.elm-lang.org/edit/Mario.elm
  • 50. lounge / Kraków / 16.02.2016@miciek Links ■ Backend project: https://github.com/miciek/mr-stats-haskell- servant ■ Frontend project: https://github.com/miciek/mr-stats-frontend- elm ■ Elm architecture tutorial: https://github.com/evancz/elm- architecture-tutorial ■ Haskell Servant: https://github.com/haskell-servant/servant ■ Let’s be mainstream - user-focused design in Elm: https://www. youtube.com/watch?v=oYk8CKH7OhE ■ Monad Transformers: https://www.youtube.com/watch? v=pzouxmWiemg ■ Make the backend team jealous - Elm in Production: https://www. youtube.com/watch?v=FV0DXNB94NE ■ Children do projects using Elm: http://outreach.mcmaster. ca/tutorials/shapes/shapes.html
  • 51. lounge / Kraków / 16.02.2016 PURELY FUNCTIONAL WEB APPS Michał Płachta www.michalplachta.com @miciek THANK YOU!