SlideShare a Scribd company logo
F# on the Server-Side       Tomáš Petříčekhttp://tomasp.net/blog	 | @tomaspetricek
About meWrote book about F#Introduce functional conceptsand F# to C# developersWorked with the F# teamContributed to VS 2010 integrationReactive programming researchFirst blog post about F# in May 2006
Server-side specificsReliability and scalability is essentialMany concurrent requestsMany I/O bound operationsExist to share state with clientsWe need different programming style!
Plan of the talk
Event-based styleProgramming using explicit callbacksSolves part of the problemInherently concurrent modelAvoids blocking of threadsGaining popularity (e.g. Node.js)HttpServer.Start("http://localhost:8080/", fun ctx -> WebClient.DownloadAsync(getProxyUrl(ctx), fun data ->    ctx.ResponseStream.WriteAsync(data, fun res ->      ctx.ResponseStream.Close())))
Limitations of event-based styleWhat we really wanted to write?What we really should write…let data = WebClient.DownloadAsync(getProxyUrl(ctx))ctx.ResponseStream.WriteAsync(data)ctx.ResponseStream.Close()try  let data = WebClient.DownloadAsync(getProxyUrl(ctx))ctx.ResponseStream.WriteAsync(data)finallyctx.ResponseStream.Close()
Plan of the talk
F# asynchronous workflowsWrite usual sequential codeAsynchronous calls using let!and do!Supports all F# control-flow constructslet copyPageTourloutputStream = async { try     let! html = WebClient.AsyncDownload(url)do! outputStream.AsyncWrite(html) finally ctx.ResponseStream.Close()}
F# asynchronous workflowsTranslated using some primitive operationsLooks similar to event-based programs…Many thanks to Haskell for Monads™!let copyPageTourloutputStream = async.TryFinally(async.Bind(WebClient.AsyncDownload(url), fun html -> async.Bind( outputStream.AsyncWrite(html),async.Zero() )),fun () ->ctx.ResponseStream.Close())
DemoHTTP proxy using asynchronous workflows
Plan of the talk
Agent-based programmingProgram consists of agents (processes)Lightweight and asynchronousAgents communicate via messagesThread-safe and queuedEnables parallelismDifferent agents vs. multiple instancesMany thanks to Erlang for Agents™!
Simple agent in F#Send Hello to the callerWaiting for message is asynchronousCan perform long-running I/O before replyingCalling agent asynchronouslyletecho = Agent.Start(fun agent -> async { while true dolet!name, rchan= agent.Receive()rchan.Reply("Hello "+ name) })let!str = echo.PostAndAsyncReply(funch-> "Tomas", ch)
DemoCaching web pages using agent
Summary and Q&AEvent-based is good starting pointF# workflow syntax really helpsAsynchronous workflows enable agentsUse agents for server-side state

More Related Content

PPSX
Golang getting started
PDF
Ruxmon.2015-08.-.proxenet
PDF
Add a backend and deploy!
PDF
Integrating Node.js with PHP
PPTX
Asp.net c# mvc Training: Day-3 of Day-9
PDF
Stockholm JAM September 2018
PDF
Intro to React
Golang getting started
Ruxmon.2015-08.-.proxenet
Add a backend and deploy!
Integrating Node.js with PHP
Asp.net c# mvc Training: Day-3 of Day-9
Stockholm JAM September 2018
Intro to React

What's hot (17)

PPT
Ruby on rails intro
PPTX
Asynchronous Programming in .NET
PDF
Build a chatroom!
PPTX
Java script
ODP
Search as a Service with Xapian - Search Solutions 2009
PPT
Fast Slim Correct: The History and Evolution of JavaScript.
PPTX
Asp.net c# mvc Training-Day-5 of Day-9
PDF
Compiling To Web Assembly
PDF
Introduction to webpack and babel
PDF
Nginx, PHP and Node.js
PDF
Building End to-End Web Apps Using TypeScript
ODP
Glance rebol
PPTX
Ddd melbourne 2011 C# async ctp
PDF
Calling java from a bash script 5
PDF
The Future starts with a Promise
PDF
Consider the following BNF grammar: implement a recursive descent parser tha...
PDF
Crystal
Ruby on rails intro
Asynchronous Programming in .NET
Build a chatroom!
Java script
Search as a Service with Xapian - Search Solutions 2009
Fast Slim Correct: The History and Evolution of JavaScript.
Asp.net c# mvc Training-Day-5 of Day-9
Compiling To Web Assembly
Introduction to webpack and babel
Nginx, PHP and Node.js
Building End to-End Web Apps Using TypeScript
Glance rebol
Ddd melbourne 2011 C# async ctp
Calling java from a bash script 5
The Future starts with a Promise
Consider the following BNF grammar: implement a recursive descent parser tha...
Crystal
Ad

Similar to F# on the Server-Side (20)

PDF
Concurrecny inf sharp
PDF
F# and SignalR for a FastWeb
PPTX
F# on the Web
PDF
F#语言对异步程序设计的支持
PPTX
Domain Modeling & Full-Stack Web Development F#
PPTX
F# Server-side programming
PDF
Asynchronous programming in F# (QCon 2012)
PDF
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
ODP
Asynchronous I/O in NodeJS - new standard or challenges?
PPTX
Async and Parallel F#
PPTX
Async and Parallel F#
PPTX
What's so special about node.js
PPTX
F# for Trading
PPTX
Reactive fsharp
PDF
ReactiveCocoa - Functional Reactive Programming concepts in iOS
PPTX
F# Tutorial @ QCon
PPTX
Mobile F#un
PPTX
Building Better Web Apps with F#
PDF
The Evolution of Async-Programming (SD 2.0, JavaScript)
PPTX
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Concurrecny inf sharp
F# and SignalR for a FastWeb
F# on the Web
F#语言对异步程序设计的支持
Domain Modeling & Full-Stack Web Development F#
F# Server-side programming
Asynchronous programming in F# (QCon 2012)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
Asynchronous I/O in NodeJS - new standard or challenges?
Async and Parallel F#
Async and Parallel F#
What's so special about node.js
F# for Trading
Reactive fsharp
ReactiveCocoa - Functional Reactive Programming concepts in iOS
F# Tutorial @ QCon
Mobile F#un
Building Better Web Apps with F#
The Evolution of Async-Programming (SD 2.0, JavaScript)
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Ad

More from Tomas Petricek (17)

PDF
Coeffects: A Calculus of Context-Dependent Computation
PPTX
Domain Specific Languages: The Functional Way
PPTX
F# Data: Making structured data first class citizens
PDF
Doing data science with F# (BuildStuff)
PDF
Doing data science with F#
PPTX
F# and Financial Data Making Data Analysis Simple
PPTX
Creating Domain Specific Languages in F#
PPTX
How F# Learned to Stop Worrying and Love the Data
PPTX
Information-rich programming in F# (ML Workshop 2012)
PPTX
F# Type Providers in Depth
PPTX
Queries in general purpose languages
PPTX
Docase notation for Haskell
PPT
Accessing loosely structured data from F# and C#
PPTX
Teaching F#
PPTX
F# in MonoDevelop
PPTX
Academia
PPTX
Concurrent programming with Agents
Coeffects: A Calculus of Context-Dependent Computation
Domain Specific Languages: The Functional Way
F# Data: Making structured data first class citizens
Doing data science with F# (BuildStuff)
Doing data science with F#
F# and Financial Data Making Data Analysis Simple
Creating Domain Specific Languages in F#
How F# Learned to Stop Worrying and Love the Data
Information-rich programming in F# (ML Workshop 2012)
F# Type Providers in Depth
Queries in general purpose languages
Docase notation for Haskell
Accessing loosely structured data from F# and C#
Teaching F#
F# in MonoDevelop
Academia
Concurrent programming with Agents

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Empathic Computing: Creating Shared Understanding
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Spectroscopy.pptx food analysis technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Tartificialntelligence_presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
SOPHOS-XG Firewall Administrator PPT.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Empathic Computing: Creating Shared Understanding
A comparative study of natural language inference in Swahili using monolingua...
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25-Week II
Digital-Transformation-Roadmap-for-Companies.pptx
TLE Review Electricity (Electricity).pptx
cloud_computing_Infrastucture_as_cloud_p
Spectroscopy.pptx food analysis technology
Building Integrated photovoltaic BIPV_UPV.pdf
Programs and apps: productivity, graphics, security and other tools
Diabetes mellitus diagnosis method based random forest with bat algorithm

F# on the Server-Side

  • 1. F# on the Server-Side Tomáš Petříčekhttp://tomasp.net/blog | @tomaspetricek
  • 2. About meWrote book about F#Introduce functional conceptsand F# to C# developersWorked with the F# teamContributed to VS 2010 integrationReactive programming researchFirst blog post about F# in May 2006
  • 3. Server-side specificsReliability and scalability is essentialMany concurrent requestsMany I/O bound operationsExist to share state with clientsWe need different programming style!
  • 5. Event-based styleProgramming using explicit callbacksSolves part of the problemInherently concurrent modelAvoids blocking of threadsGaining popularity (e.g. Node.js)HttpServer.Start("http://localhost:8080/", fun ctx -> WebClient.DownloadAsync(getProxyUrl(ctx), fun data -> ctx.ResponseStream.WriteAsync(data, fun res -> ctx.ResponseStream.Close())))
  • 6. Limitations of event-based styleWhat we really wanted to write?What we really should write…let data = WebClient.DownloadAsync(getProxyUrl(ctx))ctx.ResponseStream.WriteAsync(data)ctx.ResponseStream.Close()try let data = WebClient.DownloadAsync(getProxyUrl(ctx))ctx.ResponseStream.WriteAsync(data)finallyctx.ResponseStream.Close()
  • 8. F# asynchronous workflowsWrite usual sequential codeAsynchronous calls using let!and do!Supports all F# control-flow constructslet copyPageTourloutputStream = async { try let! html = WebClient.AsyncDownload(url)do! outputStream.AsyncWrite(html) finally ctx.ResponseStream.Close()}
  • 9. F# asynchronous workflowsTranslated using some primitive operationsLooks similar to event-based programs…Many thanks to Haskell for Monads™!let copyPageTourloutputStream = async.TryFinally(async.Bind(WebClient.AsyncDownload(url), fun html -> async.Bind( outputStream.AsyncWrite(html),async.Zero() )),fun () ->ctx.ResponseStream.Close())
  • 10. DemoHTTP proxy using asynchronous workflows
  • 11. Plan of the talk
  • 12. Agent-based programmingProgram consists of agents (processes)Lightweight and asynchronousAgents communicate via messagesThread-safe and queuedEnables parallelismDifferent agents vs. multiple instancesMany thanks to Erlang for Agents™!
  • 13. Simple agent in F#Send Hello to the callerWaiting for message is asynchronousCan perform long-running I/O before replyingCalling agent asynchronouslyletecho = Agent.Start(fun agent -> async { while true dolet!name, rchan= agent.Receive()rchan.Reply("Hello "+ name) })let!str = echo.PostAndAsyncReply(funch-> "Tomas", ch)
  • 14. DemoCaching web pages using agent
  • 15. Summary and Q&AEvent-based is good starting pointF# workflow syntax really helpsAsynchronous workflows enable agentsUse agents for server-side state

Editor's Notes

  • #13: Agents are lightweight and have some body running inside them