Presentation is loading. Please wait.

Presentation is loading. Please wait.

DotnetConf 11/19/2018 6:01 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.

Similar presentations


Presentation on theme: "DotnetConf 11/19/2018 6:01 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE."— Presentation transcript:

1 dotnetConf 11/19/2018 6:01 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

2 F# for the Practical Developer
dotnetConf 11/19/2018 6:01 AM F# for the Practical Developer Phillip Carter Program Manager, Visual F# © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

3 A Brief Introduction to F#
dotnetConf 11/19/2018 6:01 AM A Brief Introduction to F# © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4 A Functional First, Multi-Paradigm Language
dotnetConf 11/19/2018 6:01 AM A Functional First, Multi-Paradigm Language Mature, Open Source, Cross-platform Strongly and Statically-typed But with type inference, is less code! More on that later. Supports scripting and REPL-driven work Quickly prototype a proof of concept, or script an ad-hoc solution Powerful Core Libraries with Fsharp.Core Async Programming, Message-Passing, Data Wrangling, Sequence Processing, and more © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

5 Let’s see some code! dotnetConf 11/19/2018 6:01 AM
© 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

6 A Functional First, Multi-Paradigm Language
dotnetConf 11/19/2018 6:01 AM A Functional First, Multi-Paradigm Language Functional Programming Immutability by default Mutability is explicit rather than always present let mutable x = … // x is now mutable Less surprises in program behavior “Pit of Success” when your codebase gets larger Correct designs are natural; bug-prone ones aren’t First-Class Functions Functions can be passed as parameters to other functions let startsWithVowel firstChar = Seq.contains firstChar “AEIOUaeiou” // Scan vowel list for a match let toPigLatin name = if (startsWithVowel name.[0]) then name + “yay” else String.Concat(name.SubString(0), name.[0], “ay”) // Use a .NET string method! let makeThemPigLatin names = names |> List.map toPigLatin // passing toPigLatin function as an argument let pigLatinFruit = [“Apple”; “Banana”] |> makeThemPigLatin printfn “After translation: %A” pigLatinFruit // prints ’After Translation: [“Appleyay”; “ananaBay”]’ © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

7 A Functional First, Multi-Paradigm Language
dotnetConf 11/19/2018 6:01 AM A Functional First, Multi-Paradigm Language Functional Programming Powerful type system Type inference means significantly less boilerplate code let format s = sprintf “custom formatting! %s” s // infers the ‘s’ parameter and return type as string F# types allow you to push certain runtime behaviors into compile-time Example: Account for all cases with the Option<`T> type when parsing module Parsing = let private tryParseWith tryParseFunc s = match (tryParseFunc s) with | true, v -> Some v // Success! It parsed and there’s a value | false, _ -> None // Failed! Callers MUST account for this case now let parseDateTime s = tryParseWith System.DateTime.TryParse s open Parsing // Returns an Option<DateTime>, which you must pattern match at COMPILE TIME to use! parseDateTime “ ” © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

8 A Functional First, Multi-Paradigm Language
dotnetConf 11/19/2018 6:01 AM A Functional First, Multi-Paradigm Language Functional Programming Powerful type system Ability to easily represent more complex information with Discriminated Unions type BinarySearchTree<‘T> = | EmptyTree | Node of ‘T * BinarySearchTree<‘T> * BinarySearchTree<‘T> Units of Measure for numerical type safety [<Measure>] type Minute [<Measure>] type Second // Use type annotation to inform the compiler of the unit of measure let addMinutes (currentTime: int<Minute>) (mins: int<Minute>) = currentTime + mins addMinutes 40<Minute> // Compile Error – a good thing addMinutes 40<Minute> 12<Second> // Compile Error – a good thing addMinutes 40<Minute> 12<Minute> // Success! © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

9 A Functional First, Multi-Paradigm Language
dotnetConf 11/19/2018 6:01 AM A Functional First, Multi-Paradigm Language Object-Oriented Programming Full OOP Support Classes, Interfaces and Abstract Classes, Inheritance, Generics type Vector2D(dx: float, dy: float) = let length = sqrt (dx*dx + dy*dy) // private function; not visible outside Vec2 member val DX = dx with get, set // Public auto-property member this.DY = dy // Immutable public property member private this.Length = length // Immutable private property member this.Scale(k) = Vec2D(k + this.DX, k * this.DY) // Public method type ILogger = // Interfaces are types with only function signatures abstract member Log: string -> string // Takes a string; returns a string type Car(engine, fourWheels) = inherit Vehicle(engine) // `inherit` is how you derive a base class © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

10 A Functional First, Multi-Paradigm Language
dotnetConf 11/19/2018 6:01 AM A Functional First, Multi-Paradigm Language Object-Oriented Programming Full OOP Support Object Expressions Implement interfaces on the fly, as you need them Example use case: mocking a simple interface without needing a mocking library open Xunit // From the Xunit NuGet package open MyProject.Services // A namespace with a function called ‘getAndDeserializeJson’ let mockJsonService = { new IGetJsonService with // ‘new IInterface with …’ is the Object Expression member this.getJson url } [<Fact>] let ``Service Deserializes number correctly``() = let fakeUrl = “ let result = getAndDeserializeJson mockJsonService fakeUrl Assert.Equal(42, result) © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

11 A Functional First, Multi-Paradigm Language
dotnetConf 11/19/2018 6:01 AM A Functional First, Multi-Paradigm Language Runs on .NET and it’s Supported A .NET language Access to every amazing .NET library Can call C# or VB code from F# Can call F# code from C# or VB Tooling in Visual Studio Intellisense, Reactoring, and All-around Visual Studio Goodness Same amazing debugging support you get with C# and VB Intensely devoted OSS community Language and Compiler is OSS Vast collection of powerful 3rd party libraries and tools Supported and Actively Developed by Microsoft Language and tooling developed on GitHub (github.com/Microsoft/VisualFSharp) OSS contributions welcome! © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12 Demo: Extending a Web App
dotnetConf 11/19/2018 6:01 AM Demo: Extending a Web App © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

13 There’s so much more Amazing features I didn’t cover
dotnetConf 11/19/2018 6:01 AM There’s so much more Amazing features I didn’t cover Computation Expressions A general purpose mechanism for managing data, control, and side effects Example – async programming: open FSharp.Data let fetchHtmlAsync url = async { return! Http.AsyncRequestString url } Messages and Agents MailboxProcessor<‘T> - an actor model for concurrent programming built into FSharp.Core Message passing feels like it’s built right into the language` Type Providers Component which provides types, properties, and members for consuming data “Automatic” access to any data if you have a type provider Json, SQL, CSV, Yaml, XML, and so many more Huge OSS community involvement in building tons of high quality type providers © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

14 dotnetConf 11/19/2018 6:01 AM © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt "DotnetConf 11/19/2018 6:01 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE."

Similar presentations


Ads by Google