1 / 10

Introduction to F#

Introduction to F#. Kit Eason - @ kitlovesfsharp – www.kiteason.com – kit.eason@gmail.com. F# in a nutshell. Microsoft first class supported language for .NET Supports OO and functional paradigms Compiles to CLI like C#, VB.Net First class citizen in VS2010 through VS2013

tana
Download Presentation

Introduction to F#

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to F# Kit Eason - @kitlovesfsharp – www.kiteason.com – kit.eason@gmail.com

  2. F# in a nutshell • Microsoft first class supported language for .NET • Supports OO and functional paradigms • Compiles to CLI like C#, VB.Net • First class citizen in VS2010 through VS2013 • Open source, runs on Mono • Strongly typed

  3. let it be • Use ‘let’ to declare functions and values let a =1 letAdd x y = x +y letCircleArea r =System.Math.PI* r **2.

  4. Point of no return (-statements) • The return value of the function is the last value calculated (no ‘return’ statement) letStrToDoubleDefaultstrdef= let ok, result = System.Double.TryParse str if ok then result else def

  5. Yeah, it’s magic • Types are inferred – at design time

  6. The bonfire of the parentheses • Lexical scope is determined by indentation • Argument lists don’t have brackets (normally) letStrToDoubleDefaultstrdef= let ok, result = System.Double.TryParse str if ok then result else def

  7. |> operator makes you :) • “Forward pipe” • Takes output from previous operation… • …and feeds it as input to the next letAbsSquareRoot (n : double) = n |> abs |>sqrt // sqrt(abs(n))

  8. F# Interactive (FSI) • Use F# Interactive to define and try out functions > let add x y = x + y;; val add : x:int -> y:int -> int > add 3 4;; val it : int = 7 >

  9. Array module • Provides operations that work on whole arrays • Similar to LINQ letCircleArea r =System.Math.PI* r **2. let circles = [|3.; 5.2; 9.9|] letTotalArea radii = radii |> Array.sumBy (fun r -> CircleArea r)

  10. Array.filter • Another operation from the Array module • Returns an array with just the elements that pass the test let transactions = [|310.99; -52.80; 99.99; -128.30; 58.25|] letTotalCreditstxns= txns |>Array.filter (fun t -> t >0.) |>Array.sum

More Related