The document discusses getting started with F# web development. It provides an overview of F# and compares it to C#, demonstrates F# concepts like pattern matching, and shows examples of building web applications and services with F# using frameworks like ASP.NET MVC, Web API, Service Stack, Nancy and Azure. It also discusses reactive and asynchronous programming in F# for web development.
5. 5 June 16, 2012
Daniel Mohl
F# MVP and C# Insider
danmohl@gmail.com
www.twitter.com/dmohl
blog.danielmohl.com
6. 6 June 16, 2012
What Are We Doing?
Why F#?
F# Primer/Review
F#/C# ASP.NET MVC 4 Example
ASP.NET Web API, Service Stack, Nancy,
Frank
Windows Azure
WebSharper Example
7. 7 June 16, 2012
Why Functional? Why F#?
Simple Code to Solve Complex Problems
Terse Yet Readable
Less Errors
The Move to Multi-core (immutable by default)
Programming in the Small (Single Responsibility
Principle)
Higher Level Language Provides Optimization
Opportunities
Code That is Correct More Often
Features Not In Other Mainstream Languages
Staying Ahead of the Competition
Why Functional Programming Matters
F# in the Enterprise
8. 8 June 16, 2012
Why F# for Web Dev?
Asynchronous Workflows and Reactive
Programming
F#/JavaScript Commonalities
Easier to support next generation web
development
HTML5 (Web Sockets, Canvas)
Asynchronous and Reactive Programming
Web Socket Example
Canvas Example
Twitter Feed Sample (Reactive Programming)
9. 9 June 16, 2012
F# Primer/Review
Whitespace Matters
The let Keyword
Pattern Matching
More During the Demos
10. 10 June 16, 2012
Whitespace Matters
//F# //C#
open System using System;
let doSomething val =
namespace ConsoleApplication1
val + val
{
Console.WriteLine class Program
(doSomething 1) {
static int doSomething(int val)
{
return val + val;
}
static void Main(string[] args)
{
Console.WriteLine(
doSomething(1));
}
}
}
11. 11 June 16, 2012
The let Keyword
//F# //C#
open System using System;
let val2 = 1
namespace ConsoleApplication1
let doSomething val =
{
val + val2 class Program
Console.WriteLine {
(doSomething 1) static int val2 = 1;
static int doSomething(int val)
{
return val + val2;
}
static void Main(string[] args)
{
Console.WriteLine(
doSomething(1));
}
}
12. 12 June 16, 2012
Pattern Matching
Kind of like a switch/case statement, but so
much more!
Example 1:
let boolVal = true
match boolVal with
| true -> printf “was true”
| _ -> printf “was not true”
Example 2:
let name = "Dan", "Mohl"
match name with
| _, "Smith" -> printf "Found a Smith"
| "Don", _ -> printf "Found a Don"
| "Dan", "Mohl" -> printf "Found Dan Mohl"
| _ -> printf "Name not found"
13. 13 June 16, 2012
A Few General Examples
Sample F# Script (Simple Strategy Pattern
Example)
Fetch Museum List (Async Example)
Twitter Feed (Reactive Programming
Example)
Interactive DirectX
14. 14 June 16, 2012
F#/C# ASP.NET MVC 4
Example
http://visualstudiogallery.msdn.microsoft.co
m/3d2bf938-fc9e-403c-90b3-8de27dc23095
15. 15 June 16, 2012
F#/C# ASP.NET Web API
http://visualstudiogallery.msdn.microsoft.co
m/3d2bf938-fc9e-403c-90b3-8de27dc23095
19. 19 June 16, 2012
Other Web Frameworks
- Service Stack
- Nancy
- Frank
20. 20 June 16, 2012
F# and Azure
- Fog - https://github.com/dmohl/Fog
21. 21 June 16, 2012
WebSharper Example
http://visualstudiogallery.msdn.microsoft.co
m/en-us/288b94ea-0ea7-4dde-8906-
f72eb22fbe1b
Check out http://fpish.net for an example
of a live site built with WebSharper.
22. 22 June 16, 2012
More Information
Books - http://msdn.microsoft.com/en-
us/fsharp/gg262865.aspx
F# MSDN - http://msdn.microsoft.com/en-
us/fsharp/gg262865.aspx
Blogs
Twitter
Ask – F# has the greatest community around
23. 23 June 16, 2012
Daniel Mohl
F# MVP and C# Insider
danmohl@gmail.com
www.twitter.com/dmohl
blog.danielmohl.com