O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Cross platform native development in f#

132 visualizações

Publicada em

A short presentation on F# and using the Xamarin Toolchain to build cross-platform applications on Android, Windows, iOS, and Mac.

Given at Vancouver Functional Programmers, July 25, 2017.

Publicada em: Tecnologia
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Cross platform native development in f#

  1. 1. Cross-platform Native Development in F# David Y. Kay
  2. 2. ?
  3. 3. ALGOL Lisp ISWIM ML
  4. 4. F# Syntax Overview (Several examples are from: F# For Fun and Profit)
  5. 5. Basic Values // ======== "Variables" (but not really) ========== // The "let" keyword defines an (immutable) value let myInt = 5 let myFloat = 3.14 let myString = "hello" //note that no types needed // ======== Lists ============ let twoToFive = [2;3;4;5] // Square brackets create a list with // semicolon delimiters. let oneToFive = 1 :: twoToFive // :: creates list with new 1st element // The result is [1;2;3;4;5] let zeroToFive = [0;1] @ twoToFive // @ concats two lists
  6. 6. Functions let square x = x * x // Note that no parens are used. square 3 // Now run the function. Again, no parens. let add x y = x + y // don't use add (x,y)! It means something // completely different. add 2 3 // Now run the function. // to define a multiline function, just use indents. No semicolons needed. let evens list = let isEven x = x%2 = 0 // Define "isEven" as an inner ("nested") function List.filter isEven list // FP’s classic filter a la “map/filter/reduce” evens oneToFive // Now run the function
  7. 7. Pattern Matching let simplePatternMatch = let x = "a" match x with | "a" -> printfn "x is a" | "b" -> printfn "x is b" | _ -> printfn "x is something else" // underscore matches anything let validValue = Some(99) let invalidValue = None let optionPatternMatch input = match input with | Some i -> printfn "input is an int=%d" i | None -> printfn "input is missing"
  8. 8. Data Types - I // Tuple types are pairs, triples, etc. Tuples use commas. let twoTuple = 1,2 let threeTuple = "a",2,true // Record types have named fields. Semicolons are separators. type Person = {First:string; Last:string} let person1 = {First="john"; Last="Doe"}
  9. 9. Data Types - II // Union types have choices. Vertical bars are separators. type Temp = | DegreesC of float | DegreesF of float let temp = DegreesF 98.6 // Types can be combined recursively in complex ways. // E.g. here is a union type that contains a list of the same type: type Employee = | Worker of Person | Manager of Employee list let jdoe = {First="John";Last="Doe"} let worker = Worker jdoe
  10. 10. Classes type LoginWindowViewModel(overseer: Overseer.Overseer) = inherit ViewModelBase() let mutable username = "" let mutable password = "" member this.Username with get () = username and set (value) = username <- value member this.Password with get () = password and set (value) = password <- value member this.LoginCommand = ViewModelHelpers.createCommand (fun o -> overseer.login (username, password)) (fun _ -> true)
  11. 11. Interop // Mostly very great: deviceContext.SoundPlayer.MessageReceived() // Some issues, including null-safety: let x: int option = Some 4
  12. 12. Cross-platform Development (Powered by Xamarin)
  13. 13. Xamarin
  14. 14. MVVM
  15. 15. Device-specific Services
  16. 16. Thanks!
  17. 17. Contact www.davidykay.com/newsletter/ davidykay@gmail.com

×