SlideShare a Scribd company logo
Functional
Web Applications
using
F# and Suave
@TomasJansson
BEKK
Developer
Practice lead .NET
OsloFSharp/NNUG
Microsoft MVP
F# enthusiast
F#?
Flickr: Supportive / Scott Robinson/ Creative Commons
Solid foundation
Flickr: Lego Bricks/ Benjamin Esham / Creative Commons
Composability
Flickr: Lego Set 10143 Death Star Todesstern / Dude of Lego/ Creative Commons
Composability
Feedback
Why F# and
Web?
All applications are functions,
also web applications
Server
Request
Response
Server
Request Response
Function
Input Output
?
Suave is a lightweight, non-blocking web server. The non-
blocking I/O model is efficient and suitable for building fast,
scalable network applications. In fact, Suave is written in a
completely non-blocking fashion throughout. Suave runs on
Linux, OS X and Windows flawlessly.
https://suave.io/
HttpContext
WebPart
Combinators
HttpContext
WebPart
WebPart
Combinators
Combinators
… that create a WebPart from more primitive values
… that combine multiple WebParts to a single WebPart
Model (simplified)
fun funfun
1. Start with some functions or values
WebPartWebPartWebPart
Model (simplified)
fun funfun
1. Start with some functions or values
2. Apply one or more combinator to each function or value to create some WebParts
WebPart
Model (simplified)
1. Start with some functions or values
2. Apply one or more combinator to each function or value to create some WebParts
3. Apply a combinator to the WebParts to create a single WebPart (repeat if needed)
WebPartWebPartWebPart
fun funfun
Demo
Demo
http://fsharp.github.io/FAKE/http://fsprojects.github.io/Paket/
Paket FAKE
Summary
F# is awesome
The web is functional
Program the web
using Suave
Resources
https://suave.io/
https://github.com/SuaveIO/suave
https://www.gitbook.com/book/theimowski/suave-music-store/
https://github.com/mastoj/my-share
Functional webapplicaations using fsharp and suave
FP Lab Hour
Room 10 at 13:40
Functional webapplicaations using fsharp and suave
@TomasJansson
github.com/mastoj
slideshare.net/mastoj

More Related Content

KEY
Writing Your First Plugin
PPTX
Tipping the Scale - Eyal Eizenberg
PDF
Git and Github - a 90 Minute interactive workshop
ZIP
Titanium @ Minnebar
PPTX
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
PDF
Puppet powershell
PPTX
Lessons Learned From Applications That Kicked Titanium's Ass
PPT
Opening the mobile web mozilla and firefox os-chit thiri maung
Writing Your First Plugin
Tipping the Scale - Eyal Eizenberg
Git and Github - a 90 Minute interactive workshop
Titanium @ Minnebar
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
Puppet powershell
Lessons Learned From Applications That Kicked Titanium's Ass
Opening the mobile web mozilla and firefox os-chit thiri maung

What's hot (20)

PDF
Introduction to Meteor - Worldwide Meteor Day
PPT
Cross Platform Mobile Development in C#
PPTX
Building Chatbots
PDF
JavaScript as a First-Class Citizen on iOS 7
PPTX
Chatbots
PDF
See the time on your wrist - Apple Watch presentation
PDF
WP REST API - Adding Your Own Endpoint
PDF
AngularJS on Mobile with the Ionic Framework
PDF
An Introduction to ReactNative
KEY
Contextual Final
PPTX
Write Better JavaScript
PDF
IBM Sametime 9 Installation Woes and Proactive Repairs by Keith Brooks
PDF
Developing Single Page Apps with Ember.js
PPT
OpenNTF Blast from ILUG 2007
KEY
Skip the IDE with PhoneGap Build
PDF
Make web as webapp
PDF
Merging two big Symfony based applications - SymfonyCon 2017
PDF
Tipping the scale - Eyal Eizenberg - Wix
PDF
Build social apps for Facebook
PDF
Live Coverage at The New York Times
Introduction to Meteor - Worldwide Meteor Day
Cross Platform Mobile Development in C#
Building Chatbots
JavaScript as a First-Class Citizen on iOS 7
Chatbots
See the time on your wrist - Apple Watch presentation
WP REST API - Adding Your Own Endpoint
AngularJS on Mobile with the Ionic Framework
An Introduction to ReactNative
Contextual Final
Write Better JavaScript
IBM Sametime 9 Installation Woes and Proactive Repairs by Keith Brooks
Developing Single Page Apps with Ember.js
OpenNTF Blast from ILUG 2007
Skip the IDE with PhoneGap Build
Make web as webapp
Merging two big Symfony based applications - SymfonyCon 2017
Tipping the scale - Eyal Eizenberg - Wix
Build social apps for Facebook
Live Coverage at The New York Times
Ad

Similar to Functional webapplicaations using fsharp and suave (20)

PDF
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
PPTX
Expo - Zero to App.pptx
PDF
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
PPTX
Building Better Web Apps with F#
PDF
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
PDF
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
PDF
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
PDF
Developing FirefoxOS
PPT
Bay NET Aug 19 2009 presentation ppt
PPTX
Building Better Web Apps with F#
PDF
Videogram - Building a product with Sencha Touch
PDF
Top 11 Front-End Web Development Tools To Consider in 2020
PDF
Building windows phone_apps_-_a_developers_guide_v7_no_cover
PPTX
Domain Modeling & Full-Stack Web Development F#
PPT
Lightning In The Clouds
PDF
What is Codename One - Transcript.pdf
PDF
LAP II - Lezione 01 Introduzione al corso
PDF
Visual Basic in easy steps Covers Visual Basic 2015 Fourth Edition Mcgrath
PDF
Web or SDK Development
DOC
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
Expo - Zero to App.pptx
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
Building Better Web Apps with F#
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic NET 1st edi...
Developing FirefoxOS
Bay NET Aug 19 2009 presentation ppt
Building Better Web Apps with F#
Videogram - Building a product with Sencha Touch
Top 11 Front-End Web Development Tools To Consider in 2020
Building windows phone_apps_-_a_developers_guide_v7_no_cover
Domain Modeling & Full-Stack Web Development F#
Lightning In The Clouds
What is Codename One - Transcript.pdf
LAP II - Lezione 01 Introduzione al corso
Visual Basic in easy steps Covers Visual Basic 2015 Fourth Edition Mcgrath
Web or SDK Development
Ad

More from Tomas Jansson (12)

PPTX
F# as our day job by 2016
PPTX
What does the future hold for us in asp.net 5
PPTX
Polyglot heaven
PPTX
OWIN Web API with Linky
PPTX
PPTX
File -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
PPTX
Getting started with Elasticsearch and .NET
PPTX
Deployment taken seriously with Octopus Deploy and TeamCity
PPTX
State or intent
PPTX
NServiceBus workshop presentation
PPTX
SignalR - Building an async web app with .NET
PPTX
REST for .NET - Introduction to ASP.NET Web API
F# as our day job by 2016
What does the future hold for us in asp.net 5
Polyglot heaven
OWIN Web API with Linky
File -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
Getting started with Elasticsearch and .NET
Deployment taken seriously with Octopus Deploy and TeamCity
State or intent
NServiceBus workshop presentation
SignalR - Building an async web app with .NET
REST for .NET - Introduction to ASP.NET Web API

Recently uploaded (20)

PDF
Why Today’s Brands Need ORM & SEO Specialists More Than Ever.pdf
PPTX
Discovering the LMA Course by Tim Han.pptx
PPTX
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX
PPTX
_+✅+JANUARY+2025+MONTHLY+CA.pptx current affairs
PPTX
Condensed_Food_Science_Lecture1_Precised.pptx
PDF
esg-supply-chain-webinar-nov2018hkhkkh.pdf
PPTX
Sports and Dance -lesson 3 powerpoint presentation
PDF
Prostaglandin E2.pdf orthoodontics op kharbanda
PPTX
The Stock at arrangement the stock and product.pptx
PPTX
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
PPTX
1-4 Chaptedjkfhkshdkfjhalksjdhfkjshdljkfhrs.pptx
PPTX
Job-opportunities lecture about it skills
DOCX
How to Become a Criminal Profiler or Behavioural Analyst.docx
PDF
HR Jobs in Jaipur: 2025 Trends, Banking Careers & Smart Hiring Tools
PPTX
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
PDF
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
PPT
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
PPTX
ESD MODULE-5hdbdhbdbdbdbbdbdbbdndbdbdbdbbdbd
PPTX
退学买新西兰毕业证(WelTec毕业证书)惠灵顿理工学院毕业证国外证书制作
PPT
APPROACH TO DEVELOPMENTALlllllllllllllllll
Why Today’s Brands Need ORM & SEO Specialists More Than Ever.pdf
Discovering the LMA Course by Tim Han.pptx
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX
_+✅+JANUARY+2025+MONTHLY+CA.pptx current affairs
Condensed_Food_Science_Lecture1_Precised.pptx
esg-supply-chain-webinar-nov2018hkhkkh.pdf
Sports and Dance -lesson 3 powerpoint presentation
Prostaglandin E2.pdf orthoodontics op kharbanda
The Stock at arrangement the stock and product.pptx
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
1-4 Chaptedjkfhkshdkfjhalksjdhfkjshdljkfhrs.pptx
Job-opportunities lecture about it skills
How to Become a Criminal Profiler or Behavioural Analyst.docx
HR Jobs in Jaipur: 2025 Trends, Banking Careers & Smart Hiring Tools
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
ESD MODULE-5hdbdhbdbdbdbbdbdbbdndbdbdbdbbdbd
退学买新西兰毕业证(WelTec毕业证书)惠灵顿理工学院毕业证国外证书制作
APPROACH TO DEVELOPMENTALlllllllllllllllll

Functional webapplicaations using fsharp and suave

Editor's Notes

  • #2: Good morning everyone and welcome to this talk about functional programming and web applications. Web applications in the context of this talk is server side web applications, or web apis. You can implement client side applications using a F# project call Fable if you want to, but that is not in scope for this talk. Before I go any further I would like to know a little bit more about you. How many know F#? How many here have used Suave?
  • #3: Let me introduce myself. My name is Tomas Jansson and I work as a manager at Bekk Consulting here in Oslo, where I am the practice lead of .NET. Even though my title is manager, it is just a label, I am a developer like most of you I guess and that is what I do most of the time. The customer I work for is in the public sector and we have brought in F# in some of our solutions there. I hope to see a wider adoption in the long run, but it is a long walk a head of us to get there. When I’m not working and not relaxing at home I’m also engaged in the community. I lead the NNUG Group here in Oslo and is also the initator of OsloFSharp which is a subgroup of NNUG for practical reasons which we started about this time last year and already have more than 200 members already. I am a Microsoft MVP and F# enthusiast.
  • #4: What is F# and why should you care? Let’s first answer the what part, since that is more concrete and nothing you can argue It started of at Microsoft Research but it is fully open source and it is now the FSharp Foundation that maintains the open-source code repository. F# is a functional first language with it roots in the ML tree of languages that runs on the .NET platforms. That means it runs on both the CLR on Windows and Mono on linux systems. There is work going on to get F# to run on dotnetcore and you can try that out today if you want to. That was what F# is, but why do I like F# and why should you consider it?
  • #5: Strong typing  if it compiles it most likely runs Not null  Tony Hoare, who introduced it in algol in the year of 65 I think, called it his billion dollar mistake. It is hard to reason and deal with null, so just not having it is easer. Take a list structure in C#, what does it mean when the list is null? Is it empty or did an error occur. That’s really hard to know without looking through the implementation details. Immutability by default  when things are immutable it is much easier to reason of what the state of something is since nothing can change the state. Every time you need to change something that is immutable you create a new copy instead, It’s not as expensive at it sounds and the syntax support for it makes it as easy as setting a property in C#. Structural equality  this just make sense. When comparing things you actually check what the values are instead of checking by reference which is the default in C#. No matter what you compare in F# it works the same way. This is as long as you use types defined in F# and not doing weird things.
  • #6: Composability is one of the most important concepts in F#. Can compose types and functions in an easy manner. Making it easy to from this to…
  • #7: This. Terrifying deathstar You can compose things in most languages, but the question is how easy it is to do so and how much noise it introduces. The syntax of F# makes it really easy to compose types from other types, without any boiler plate, it also makes it really easy to write functions and combine functions to form a whole in an easy manner. We will see some of this in the demo later on.
  • #8: Feedback in many levels - Amazing eco-system with a lot of open source projects and active community. This is probably one of the things I like the most with F#. Everyone in the community is super smart and really helpful. - The next level of feedback is when you code and use the REPL. The REPL makes really easy to do some fast prototyping and experiments before turning the code into a library, if you wish. - Feedback also comes in the form of testing. I would say that the way you write functional code tend to make it much easier to test, since that is what you do constantly in the the REPL. Converting things you wrote in the REPL to a test for more feedback in the long run is really easy as well.
  • #9: But F# and web? #wat?
  • #10: I would go as far as to say that all applications are functions! And since web applications are applications they are also functions. What do I mean?
  • #11: Most people thing of a web applications like this. You have some kind of client that makes a request to the server and get a response back. This is only a mental model.
  • #12: But what if you just change the arrows as a first attempt to change your mental model of a web application.
  • #13: When you have done the first step it’s not hard to see that this is exactly what a function is. This brings us to the last part of me just talking and that is.
  • #15: It will also run on dotnetcore when all the F#-bits are ready. There is already some bits running on dotnetcore, but I haven’t tried it yet. I have tried it on mono and Windows and the programming experience using Suave hits a sweet spot for me at least. You get a lot of control, and at the same time it is really easy to get started. It is implemented in F# for F# to be a idiomatic functional web framework, compared with for example asp.net which you also can use together with F# if you want to.
  • #16: The three most imporntat concepts in Suave according to me are these three. And I will go into a little bit more detail before showing them in practice.
  • #17: The context is what holds all the request and response data through a web request. Each request basically starts with a default context and then you create new contexts, remember that F# is immutable, through a series of steps.
  • #18: Those steps are WebParts.
  • #19: The signature of a webpart looks like this. Which basically reads, take a HttpContext as input, return a async computation that returns either Some of a new HttpContext or None if this WebPart should be skipped.
  • #20: This is the glue that glues web parts together.
  • #21: This is the glue that glues web parts together.
  • #22: This is how it is defined bottom up. You start with a set of functions or values, it could be a function that looks something up in a database, a function that renders html, or something that modifies a header value, ot it could even be a ready WebPart.
  • #23: The next step is to apply a combinator to create a WebPart, if you have a function that returns a json object you might use a combinator to create the actual httpcontext from that object.
  • #24: If you have multiple endpoints you usually use another combinator to wrap the webparts to create a single webpart. If you then have cross-cutting concerns you migh have additional layers that wrap the last webpart. That is the simplified version of how it works, and that’s basically all there is to it.
  • #26: I will be using these two tools as well. Paket for handling packages, which is a package manager for nuget packages FAKE is a build automation system. I won’t go into details about how this two tools work, but please come ask questions afterwards if you have question regarding these two tools. But they are worth looking into even for C# devs.
  • #28: Great stricter but yet more flexible language than C# Runs great on all common platforms through clr and mono
  • #29: The web is functional, and programming web applications in a functional language can be a new amazing experience where you can combine and put together applications the same way you build lego.
  • #30: A great option if you want to program the web in a functional language is F# with Suave.