Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# F# Eye 4 the C# Guy

6,987
views

Published on

Published in: Technology

5 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
6,987
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
0
0
Likes
5
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. F# Eye 4 the C# Guy
Phillip Trelford
@ptrelford
http://trelford.com/blog
• 2.
• 3. Thoughtworks Tech RadarJuly 2011
• 4. Visual F#
• 5. The F in F# standsfor FUN
• 6. Halo 3 with F# Skills
• 7. XBLA: Path to Go – F# AI
• 8. F#
Strongly Typed
Functional
Object Orientated
Open Source
.Net language
In Visual Studio
• 9. Functional Programming
Pure Functions
Higher Order Functions
Pattern Matching
• 10. Pure Functions - Excel
• 11. Higher Order Functions
F# Map/Reduce
letmapf xs = seq {
for x inxsdo
yield f x
}
letreducefinititems =
letmutablecurrent = init
for item in items do
current <- f current item
current
C# Map/Reduce
publicstatic
IEnumerable<R> Map<T, R>
(thisIEnumerable<T> xs,
Func<T, R> f)
{
foreach (var x in xs)
yieldreturn f(x);
}
publicstatic R
Reduce<T, R>
(thisIEnumerable<T> xs,
R init,
Func<R, T, R> f)
{
varcurrent = init;
foreach (var x in xs)
current = f(current, x);
return current;
}
• 12. Pattern Matching
F#
match day with
| 0 ->"Sunday"
| 1 ->"Monday"
| 2 ->"Tuesday"
| 3 ->"Wednesday"
| 4 ->"Thursday"
| 5 ->"Friday"
| 6 ->"Saturday"
| _ –>
invalidArg"Invalid day"
C#
switch (day) {
case0: return"Sunday";
case1: return"Monday";
case2: return"Tuesday";
case3: return"Wednesday";
case4: return"Thursday";
case5: return"Friday";
case6: return"Saturday";
default:
thrownew
ArgumentException("day");
}
• 13. demos
• 14. Light Syntax
F#
type Person(name:string,age:int) =
/// Full name
memberperson.Name = name
/// Age in years
memberperson.Age = age
C#
publicclassPerson
{
public Person(string name, int age)
{
_name = name;
_age = age;
}
///<summary>
/// Full name
///</summary>
publicstring Name
{
get { return _name; }
}
///<summary>
/// Age in years
///</summary>
publicint Age
{
get { return _age; }
}
}
• 15. Unit Testing toExplorative Testing
F# NUnit
openNUnit.Framework
[<TestFixture>]
moduleMathTest =
[<Test>]
let ``2 + 2 should equal 4`` () =
Assert.AreEqual(2 + 2, 4)
C# NUnit
usingNUnit.Framework;
[TestFixture]
publicclassTest
{
[Test]
publicvoid
TwoPlusTwoShouldEqualFour()
{
Assert.AreEqual(2 + 2, 4);
}
}
• 16. Domain Model - POS
typeCode = string
type Name = string
type Price = decimal
type Product =
Product of Code * Name * Price
type Quantity = decimal
typeSaleLineItem =
Product * Quantity
• 17. F# 3.0 (Beta)Type Providers
• 18. Units of Measure
• 19. Units in Cells
typearithmeticOp =
Add | Sub | Mul | Div
typelogicalOp =
Eq| Lt | Gt | Le | Ge | Ne
type formula =
| Negof formula
| Expof formula * formula
| ArithmeticOpof
formula * arithmeticOp * formula
| LogicalOpof
formula * logicalOp * formula
| NumofUnitValue
| Ref ofint * int
| Range ofint * int * int * int
| Fun of string * formula list
• 20. SUMMARY
• 21. TIOBE Index August 2011 - F# enters Top 20
• 22. F# Jobs
• 23. Meet the F#ersTwitter #fsharp
• 24. F# Books
• 25. @jbandi
#chtd Quote from "future of .net" Have a look at F# for two days and you will find yourself two years ahead of your peer .netdevs. #fsharp
• 26. Q & A