Successfully reported this slideshow.
Upcoming SlideShare
×

Cross platform native development in f#

127 views

Published on

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.

Published in: Technology
• Full Name
Comment goes here.

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

• Be the first to like this

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