Eriawan Kusumawardhono
   F# is starting from a research project of    Microsoft, created by Don Syme   F# is a functional programming language...
   There are many definitions about this, and    there’s no simple standard definition   According to Erik Meijer and Br...
   A simple operation that returns a value, that    can have a parameter or more than one    parameters
f(x) = x+1y=x+1
x=x+1x++
F#                                 OOP (C#, VB, C++…)    Immutable by default             Mutable by default    Functio...
Comparison of F# to others such as C#, VB, C++
   Immutable by default       Mutable by default    let y = x + 1               x = x +1   Mutable is explicit        ...
   In F#, it can be              In C# and VB, it must    standalone and simple          be enclosed in a               ...
   Already have at the first release   It is also a strong type language   Including built in support of Generic   The...
Int32let avalue =10               Stringlet aName = ‘Hello’let savingInterest = 0.2           Double
   Type inference on functions when it’s used                     let f x = sqr x + 1                                    ...
Less noise syntax but it’s still strongly typed
   Always begin with keyword “let”      let avalue = 10      let aName = ‘Hello’      let savingInterest = 0.2
   When there’s a need for explicit type system:     let x:int = 0     let piConstant:float = 3.141     let Name:String =...
   Always begin with let keyword     let f x = x + 1     let sqr y = y * y     let force x = x * gravity
   Parameters are written in a nice separation    “juxtaposition” syntax: a space          let sqr x = x * x             ...
The code in F#
   Multiple lines of code is using indentation:       let rec fib x =           if x < 2 then 1           else fib (x–1) ...
   Comment is the same with VB and C#       // some code       let x = x + 2       // XML doc comment:       /// <summary...
The object oriented and imperative are here in F#
let f x = x *xlet g(x) = x* xfun x -> x * x
   Mutable is easy, by adding keyword    “mutable”   Next operation of assignment must use “<-”    to differentiate muta...
   Creating enum is also easy:                   type Suit =                       | Heart                       | Diamon...
type Vector2D(dx:float, dy:float) =    // The pre-computed length of the vector    let length = sqrt(dx*dx + dy*dy)    ///...
   It’s easy! Just create type but with abstract    keyword as modifier for all functions and    other members:          ...
Unit of measure in F# only!
[<Measure>]type kg[<Measure>]type m[<Measure>]type slet gravityOnEarth = 9.81<m/s^2>let heightOfMyOfficeWindow = 3.5<m>let...
Created by Eriawan Kusumawardhono, courtesy of RX Communica
Upcoming SlideShare
Loading in...5
×

F sharp _vs2010_beta2

120

Published on

Overview of F# on Visual Studio 2010 Beta 2

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
120
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

F sharp _vs2010_beta2

  1. 1. Eriawan Kusumawardhono
  2. 2.  F# is starting from a research project of Microsoft, created by Don Syme F# is a functional programming language that runs on top of .NET F# is now part of VS 2010 built in programming language Also part of OCAML programming language family
  3. 3.  There are many definitions about this, and there’s no simple standard definition According to Erik Meijer and Brian Beckman of Microsoft, Functional Programming is programming with mathematical function, where function is a first class citizen of a program
  4. 4.  A simple operation that returns a value, that can have a parameter or more than one parameters
  5. 5. f(x) = x+1y=x+1
  6. 6. x=x+1x++
  7. 7. F# OOP (C#, VB, C++…) Immutable by default  Mutable by default Function is the same as  Function is treated as a data in a program, and can method that must reside in be written as a standalone a body of a class function  ‘Noisy’ syntax Succinct syntax  Type inference is only Type inference is available available since C# 3.0 and from the start VB 9.0, not in C++ and others
  8. 8. Comparison of F# to others such as C#, VB, C++
  9. 9.  Immutable by default  Mutable by default let y = x + 1 x = x +1 Mutable is explicit  Immutable is explicit. For example, in C#: let mutable x = x + 1 readonly x = 0  In VB: ReadOnly x As Integer
  10. 10.  In F#, it can be  In C# and VB, it must standalone and simple be enclosed in a class/module let f x = x +2 class SimpleFunc { public static Int32 f(Int32 x) This is why it is called { return x + 2; “succinct” } }  This is “noisy”
  11. 11.  Already have at the first release It is also a strong type language Including built in support of Generic The type inference is not just local type inference, but it then can be inferred based on the use of the parameters!
  12. 12. Int32let avalue =10 Stringlet aName = ‘Hello’let savingInterest = 0.2 Double
  13. 13.  Type inference on functions when it’s used let f x = sqr x + 1 Infers integer .. return type from a whole becomes int number…let sqr x = x * x Infers double from a double literal.. let f x = sqr x + 1.0
  14. 14. Less noise syntax but it’s still strongly typed
  15. 15.  Always begin with keyword “let” let avalue = 10 let aName = ‘Hello’ let savingInterest = 0.2
  16. 16.  When there’s a need for explicit type system: let x:int = 0 let piConstant:float = 3.141 let Name:String = ‘Eriawan’
  17. 17.  Always begin with let keyword let f x = x + 1 let sqr y = y * y let force x = x * gravity
  18. 18.  Parameters are written in a nice separation “juxtaposition” syntax: a space let sqr x = x * x Function parameter let add a b = a + b
  19. 19. The code in F#
  20. 20.  Multiple lines of code is using indentation: let rec fib x = if x < 2 then 1 else fib (x–1) + fib (x-2)
  21. 21.  Comment is the same with VB and C# // some code let x = x + 2 // XML doc comment: /// <summary>A square function<summary> /// <param name=‚x‛>the value</param> let f x = x * x
  22. 22. The object oriented and imperative are here in F#
  23. 23. let f x = x *xlet g(x) = x* xfun x -> x * x
  24. 24.  Mutable is easy, by adding keyword “mutable” Next operation of assignment must use “<-” to differentiate mutability. let mutable y = 10 y <- y + 1
  25. 25.  Creating enum is also easy: type Suit = | Heart | Diamond | Spade | Club
  26. 26. type Vector2D(dx:float, dy:float) = // The pre-computed length of the vector let length = sqrt(dx*dx + dy*dy) /// The displacement along the X-axis member v.DX = dx /// The displacement along the Y-axis member v.DY = dy /// The length of the vector member v.Length = length // Re-scale the vector by a constant member v.Scale(k) = Vector2D(k*dx, k*dy)
  27. 27.  It’s easy! Just create type but with abstract keyword as modifier for all functions and other members: type IPeekPoke = abstract Peek: unit -> int abstract Poke: int -> unit
  28. 28. Unit of measure in F# only!
  29. 29. [<Measure>]type kg[<Measure>]type m[<Measure>]type slet gravityOnEarth = 9.81<m/s^2>let heightOfMyOfficeWindow = 3.5<m>let speedOfImpact = sqrt (2.0 * gravityOnEarth + heightOfMyOfficeWindow)
  30. 30. Created by Eriawan Kusumawardhono, courtesy of RX Communica
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×