19

Click here to load reader

iOS App Development with F# and Xamarin

Embed Size (px)

DESCRIPTION

With each new release of Xamarin Studio, the mobile story gets even better for functional programming. It’s possible to write fully native, cross-platform mobile apps all entirely in F#! I’ll concentrate on iOS, covering both iOS basics and F# basics -- you’ll have all the tools to run with your own idea when we're done!

Citation preview

Page 1: iOS App Development with F# and Xamarin

T W I T T E R : @ R A C H E L R E E S E

B L O G : R A C H E L R E E . S E

G I T H U B : R A C H E L R E E S E

iOS App Development with

Xamarin and F#

Page 2: iOS App Development with F# and Xamarin

Why F#?

Page 3: iOS App Development with F# and Xamarin

”Y A N C U I

L E A D S E R V E R E N G I N E E R , G A M E S Y S ( S O U R C E )

F#…offers us an order of magnitude

increase in productivity and allows one

developer to perform the work…of a

team of dedicated developers on an

existing Java-based solution...

F# Testimonials

Page 4: iOS App Development with F# and Xamarin

”D A R R E N P L A T T

A M Y R I S B I O T E C H N O L O G Y ( S O U R C E )

The UI work is especially gratifying,

because state of the art for a lot of

genomic data display is still PNG images

embedded in JavaScript and with F# I can

render half a million data points on a web

page without jumping through hoops.

F# Testimonials

Page 5: iOS App Development with F# and Xamarin

StartNewGame <| GetNewGameBoard()

F# Fundamentals

|>

Significant whitespace

Immutable by default

//names is tuple of (name, id)Array.Parallel.partition (fun g -> ids.Contains(snd g)) names

|> fst|> Array.toList

[1..10]|> List.filter (fun x -> x % 2 = 0)|> List.map (fun x -> x + 3)|> List.sum

operaHouses //(Name, Current Productions) for each opera house |> Array.map (fun (x,y) -> x, y |> Seq.toArray))|> Array.filter (fun (x,y) -> y.Length > 0)

Page 7: iOS App Development with F# and Xamarin

F# C#

type Transport =

| Car of Make:string * Model:string

| Bus of Route:int

| Bicycle

public abstract class Transport{ }

public abstract class Car : Transport {

public string Make { get; private set; }

public string Model { get; private set; }

public Car (string make, string model) {

this.Make = make;

this.Model = model;

}

}

public abstract class Bus : Transport {

public int Route { get; private set; }

public Bus (int route) {

this.Route = route;

}

}

public class Bicycle: Transport { }

...

F# Fundamentals: Concise Code with DUs

Page 8: iOS App Development with F# and Xamarin

F# Fundamentals: Pattern Matching

type Transport =| Car of Make:string * Model:string| Bus of Route:int| Bicycle

let getThereVia (transport:Transport) =match transport with

| Car (make,model) -> ()| Bus route -> ()

Page 9: iOS App Development with F# and Xamarin

Several reasons why you should learn F#

Discriminated unions

Immutable by default

Pattern matching

Option type

Custom operators

REPL

Page 10: iOS App Development with F# and Xamarin

F# vs. Swift

‘Enums’Discriminated unions

Constant or VariableImmutable by default

Enhanced switchPattern matching

OptionalsOption type

Custom operatorsCustom operators

REPLREPL

Page 11: iOS App Development with F# and Xamarin

No type providersLacks full type

inference

No units of

measureRequires “return”

Still void, no unitNo parallelism &

async!Single platform Young language

No easy cloning

syntax for

structures (e.g.

records)

Literal data

structures are only

list and dict

Simpler garbage

collection processActive Patterns

But Swift is still missing out

Page 12: iOS App Development with F# and Xamarin

TYPE PROVIDERS!

UNITS OF MEASURE!

Why F#?

Page 13: iOS App Development with F# and Xamarin

Some existing

type providers.

See here for a full list.

Minesweeper AzureChoose your

own

adventure

Matla

b RSS

XAML Rock, Paper,

Scissors Oracle MVVMCross SignalR

FunScript R File System Python Regex

CSV World Bank SQLite Don Syme XML

Squirrels LINQIKV

M

MS

Dynamics

CRM

Freebase

JSON SQL ServerSQL Server

with EFpowershell Dates

Hadoo

pOData WSDL Apiary Facebook

Page 14: iOS App Development with F# and Xamarin

Get data

from

Hadoop

SQL Server

SQLite

RSS

Freebase

Oracle

CSV

OData

World Bank

JSON

Process

with

Matlab

Powershell

Regex

R

SignalR

Python

LINQ

Visualize

with

F#

Matlab

R

Get creative.

Page 15: iOS App Development with F# and Xamarin

Why Xamarin?

Fully

Native

Cross

Platform

Page 16: iOS App Development with F# and Xamarin

iOS Fundamentals: AppDelegate

Page 17: iOS App Development with F# and Xamarin

iOS Fundamentals: ViewController

Page 18: iOS App Development with F# and Xamarin

Minesweeper

Page 19: iOS App Development with F# and Xamarin

T W I T T E R : @ R A C H E L R E E S E

B L O G : R A C H E L R E E . S E

G I T H U B : R A C H E L R E E S E

iOS App Development with

Xamarin and F#