+ All Categories
Home > Technology > Tour of language landscape

Tour of language landscape

Date post: 24-Jul-2015
Category:
Upload: yan-cui
View: 2,482 times
Download: 0 times
Share this document with a friend
285
tour guide : Yan Cui @theburningmonk
Transcript
Page 1: Tour of language landscape

tour guide : Yan Cui @theburningmonk

Page 2: Tour of language landscape

Hi, my name is Yan Cui.

Page 3: Tour of language landscape
Page 4: Tour of language landscape

1MILLION USERS

ACTIVEDAILY

Page 5: Tour of language landscape

250MILLION DAY

PERREQUEST

Page 6: Tour of language landscape

2MONTH

TBP E R

secops25,000

Page 7: Tour of language landscape

agenda

Page 8: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 9: Tour of language landscape

disclaimers

Page 10: Tour of language landscape

syntax!doesn’t matter

Page 11: Tour of language landscape
Page 12: Tour of language landscape

Being literate isn't simply a matter of being able to put words on the page, it's solidifying our thoughts such that they can be written.

Interpreting and applying someone else's thoughts is the equivalent for reading. We call

these composition and comprehension. And they are what literacy really is.

- Chris Granger

Page 13: Tour of language landscape

Coding, like writing, is a mechanical act… Just like writing, we have to know how to solidify

our thoughts and get them out of our head…!We build mental models of everything… If we want computers to be able to compute for us, then we have to accurately extract these models from our heads and record them.

- Chris Granger

Page 14: Tour of language landscape

IDEAS matter

Page 15: Tour of language landscape

“Programming languages have a devious influence: they shape our thinking

habits.”

- Edsger W. Dijkstra

Page 16: Tour of language landscape

“One of the most disastrous thing we can learn is the first programming language, even

if it's a good programming language.”

- Alan Kay

Page 17: Tour of language landscape

“Just as there are odours that dogs can smell and we cannot, as well as sounds that dogs can hear

and we cannot, so too there are wavelengths of light we cannot see and flavours we cannot taste. Why

then, given our brains wired the way they are, does the remark "Perhaps there are thoughts we cannot think," surprise you? Evolution, so far, may possibly have blocked us from being able to think in some

directions; there could be unthinkable thoughts.”

- Richard Hamming

Page 18: Tour of language landscape

“Just as there are odours that dogs can smell and we cannot, as well as sounds that dogs can hear

and we cannot, so too there are wavelengths of light we cannot see and flavours we cannot taste. Why

then, given our brains wired the way they are, does the remark "Perhaps there are thoughts we cannot think," surprise you? Evolution, so far, may possibly have blocked us from being able to think in some

directions; there could be unthinkable thoughts.”

- Richard Hamming

Page 19: Tour of language landscape
Page 20: Tour of language landscape
Page 21: Tour of language landscape
Page 22: Tour of language landscape
Page 23: Tour of language landscape

“The limits of my language means the limits of my world.”

- Ludwig Wittgenstein

Page 24: Tour of language landscape
Page 25: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 26: Tour of language landscape

your app

Page 27: Tour of language landscape

your app

CSVCSVCSV

CSVCSVXML

Page 28: Tour of language landscape

your app

CSVCSVCSV

CSVCSVXML

some service

Page 29: Tour of language landscape

your app

CSVCSVCSV

CSVCSVXML

some service

DB

Page 30: Tour of language landscape

1. define DTO types!2. I/O!3. marshal data into DTO!4. do useful work

Page 31: Tour of language landscape

1. define DTO types!2. I/O!3. marshal data into DTO!4. do useful work

Page 32: Tour of language landscape

compilerprovideexternal

data source typed info

Page 33: Tour of language landscape

type providers

Page 34: Tour of language landscape

intellisense!tooltips!

Page 35: Tour of language landscape
Page 36: Tour of language landscape
Page 37: Tour of language landscape

compile time validation

Page 38: Tour of language landscape

no code generation

Page 39: Tour of language landscape

R

FunScript AzureAmazon S3

CSVSQLiteSQL Server

WSDL

WorldBank

RegexODATA IKVM

FacebookApiary

XAMLFreebaseHadoop

Oracle

Minesweeper

Don SymePowershell

JSON

Fizzbuzz

Mixin

RSS

MatlabDates

NorthPole

XML

Python

Page 40: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 41: Tour of language landscape

“…a clean design is one that supports visual thinking so

people can meet their informational needs with a

minimum of conscious effort.”

- Daniel Higginbotham (www.visualmess.com)

Page 42: Tour of language landscape

Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage problem using a message passing approach. Naturally, I wanted to answer that question with Erlang!!!Let’s first dissect the problem and decide what processes we need and how they need to interact with one another.!!The stable marriage problem is commonly stated as:!Given n men and n women, where each person has ranked all members of the opposite sex with a unique number between 1 and n in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are “stable”. (It is assumed that the participants are binary gendered and that marriages are not same-sex).!From the problem description, we can see that we need:!* a module for man!* a module for woman!* a module for orchestrating the experiment!In terms of interaction between the different modules, I imagined something along the lines of…

how we read ENGLISH

see also http://bit.ly/1KN8cd0

Page 43: Tour of language landscape

Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage problem using a message passing approach. Naturally, I wanted to answer that question with Erlang!!!Let’s first dissect the problem and decide what processes we need and how they need to interact with one another.!!The stable marriage problem is commonly stated as:!Given n men and n women, where each person has ranked all members of the opposite sex with a unique number between 1 and n in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are “stable”. (It is assumed that the participants are binary gendered and that marriages are not same-sex).!From the problem description, we can see that we need:!* a module for man!* a module for woman!* a module for orchestrating the experiment!In terms of interaction between the different modules, I imagined something along the lines of…

2. top-to-bottom1.left-to-right

how we read ENGLISH

see also http://bit.ly/1KN8cd0

Page 44: Tour of language landscape

how we read CODE

public void DoSomething(int x, int y)!{! Foo(y,! Bar(x,! Zoo(Monkey())));!}

see also http://bit.ly/1KN8cd0

Page 45: Tour of language landscape

how we read CODE

public void DoSomething(int x, int y)!{! Foo(y,! Bar(x,! Zoo(Monkey())));!}

2. bottom-to-top

1.right-to-left

see also http://bit.ly/1KN8cd0

Page 46: Tour of language landscape

Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage problem using a message passing approach. Naturally, I wanted to answer that question with Erlang!!!Let’s first dissect the problem and decide what processes we need and how they need to interact with one another.!!The stable marriage problem is commonly stated as:!Given n men and n women, where each person has ranked all members of the opposite sex with a unique number between 1 and n in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are “stable”. (It is assumed that the participants are binary gendered and that marriages are not same-sex).!From the problem description, we can see that we need:!* a module for man!* a module for woman!* a module for orchestrating the experiment!In terms of interaction between the different modules, I imagined something along the lines of…

2. top-to-bottom

1.left-to-right

how we read ENGLISH

public void DoSomething(int x, int y)!{! Foo(y,! Bar(x,! Zoo(Monkey())));!}

2. top-to-bottom

1.right-to-left

how we read CODE

see also http://bit.ly/1KN8cd0

Page 47: Tour of language landscape

“…a clean design is one that supports visual thinking so

people can meet their informational needs with a

minimum of conscious effort.”

Page 48: Tour of language landscape

|>

Page 49: Tour of language landscape

how we read CODE

let drawCircle x y radius = radius |> circle |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)

see also http://bit.ly/1KN8cd0

Page 50: Tour of language landscape

how we read CODE

let drawCircle x y radius = radius |> circle |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)

2. top-to-bottom1.left-to-right

see also http://bit.ly/1KN8cd0

Page 51: Tour of language landscape

let drawCircle x y radius = circle radius |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)

see also http://bit.ly/1KN8cd0

Page 52: Tour of language landscape

let drawCircle x y radius = circle radius |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)

see also http://bit.ly/1KN8cd0

Page 53: Tour of language landscape

let drawCircle x y radius = circle radius |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)

see also http://bit.ly/1KN8cd0

Page 54: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 55: Tour of language landscape

NASA orbiter crashed because one engineer accidentally used miles instead of kilometres

Page 56: Tour of language landscape

you’re never too smart to make mistakes

Page 57: Tour of language landscape

unit-of-measure

Page 58: Tour of language landscape

[<Measure>]!type Pence

e.g.! 42<Pence>!! 153<Pence>!! …

Page 59: Tour of language landscape

10<Meter> / 2<Second> ! = 5<Meter/Second>!10<Meter> * 2<Second> ! = 20<Meter Second> !10<Meter> + 10<Meter> ! = 20<Meter>!10<Meter> * 10! ! ! = 100<Meter>!10<Meter> * 10<Meter> ! = 100<Meter2>!10<Meter> + 2<Second> ! // error!10<Meter> + 2 ! ! ! // error

Page 60: Tour of language landscape

10<Meter> / 2<Second> ! = 5<Meter/Second>!10<Meter> * 2<Second> ! = 20<Meter Second> !10<Meter> + 10<Meter> ! = 20<Meter>!10<Meter> * 10! ! ! = 100<Meter>!10<Meter> * 10<Meter> ! = 100<Meter2>!10<Meter> + 2<Second> ! // error!10<Meter> + 2 ! ! ! // error

Page 61: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 62: Tour of language landscape

Duck Typing

If it looks like a duck and quacks like a duck, it's a duck

Page 63: Tour of language landscape

def say_quack(duck): duck.quack()

Page 64: Tour of language landscape

def say_quack(duck): duck.quack()

Page 65: Tour of language landscape

class Duck: def quack(self): print("quack quack!”)

Page 66: Tour of language landscape

class Duck: def quack(self): print("quack quack!”) !

duck = Duck() say_quack(duck) !

> quack quack!

Page 67: Tour of language landscape

class Bird: def quack(self): print(“tweet tweet!”)

Page 68: Tour of language landscape

class Bird: def quack(self): print(“tweet tweet!”) !

bird = Bird() say_quack(bird) !

> tweet tweet!

Page 69: Tour of language landscape

ConvenienceSafety

Page 70: Tour of language landscape

what if…

Page 71: Tour of language landscape

Convenience Safety

see also http://bit.ly/1H2fN9i

Page 72: Tour of language landscape

statically resolved!

type parameters

Page 73: Tour of language landscape

let inline sayQuack (duck : ^a) = (^a : (member Quack : unit -> unit) duck)

see also http://bit.ly/1H2fN9i

Page 74: Tour of language landscape

let inline sayQuack (duck : ^a) = (^a : (member Quack : unit -> unit) duck)

see also http://bit.ly/1H2fN9i

Page 75: Tour of language landscape

let inline sayQuack (duck : ^a) = (^a : (member Quack : unit -> unit) duck)

see also http://bit.ly/1H2fN9i

Page 76: Tour of language landscape

let inline sayQuack (duck : ^a) = (^a : (member Quack : unit -> unit) duck)

see also http://bit.ly/1H2fN9i

Page 77: Tour of language landscape

type Duck () = member __.Quack() = printfn “quack quack!” !

let duck = Duck() sayQuack duck !

> quack quack!see also http://bit.ly/1H2fN9i

Page 78: Tour of language landscape

type Bird () = member __.Quack() = printfn “tweet tweet!” !

let bird = Bird() sayQuack bird !

> tweet tweet!see also http://bit.ly/1H2fN9i

Page 79: Tour of language landscape

type Dog () = member __.Bark() = printfn “woof woof!” !

let dog = Dog() sayQuack dog !error FS0001: The type ‘Dog’ does not support the operator ‘Quack’

see also http://bit.ly/1H2fN9i

Page 80: Tour of language landscape

Convenience Safety

see also http://bit.ly/1H2fN9i

Page 81: Tour of language landscape
Page 82: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 83: Tour of language landscape

implicit interface!

implementation

Page 84: Tour of language landscape

type Duck interface { Quack() }

see also http://bit.ly/1ER5zVs

Page 85: Tour of language landscape

func sayQuack(duck Duck) { duck.Quack() }

see also http://bit.ly/1ER5zVs

Page 86: Tour of language landscape

type Donald struct { } func (d Donald) Quack() { fmt.Println(“quack quack!”) }

see also http://bit.ly/1ER5zVs

Page 87: Tour of language landscape

type Bird struct { } func (b Bird) Quack() { fmt.Println(“tweet tweet!”) }

see also http://bit.ly/1ER5zVs

Page 88: Tour of language landscape

func main() { donald := Donald{} sayQuack(donald) bird := Bird{} sayQuack(bird) }

see also http://bit.ly/1ER5zVs

Page 89: Tour of language landscape

quack quack!

func main() { donald := Donald{} sayQuack(donald) bird := Bird{} sayQuack(bird) }

Page 90: Tour of language landscape

tweet tweet!

func main() { donald := Donald{} sayQuack(donald) bird := Bird{} sayQuack(bird) }

Page 91: Tour of language landscape

type Dog struct { } func (d Dog) Bark() { fmt.Println(“woof woof!”) }

see also http://bit.ly/1ER5zVs

Page 92: Tour of language landscape

func main() { dog := Dog{} sayQuack(dog) }

main.go:40: cannot use dog (type Dog) as type Duck in argument to sayQuack:!! Dog does not implement Duck (missing Quack method)

see also http://bit.ly/1ER5zVs

Page 93: Tour of language landscape

Convenience Safety

see also http://bit.ly/1ER5zVs

Page 94: Tour of language landscape

patterns are observed after the fact

see also http://bit.ly/1ER5zVs

Page 95: Tour of language landscape

system building is also a process of learning

and discovery

see also http://bit.ly/1ER5zVs

Page 96: Tour of language landscape

implementation package

interface packagesee also http://bit.ly/1ER5zVs

Page 97: Tour of language landscape

encourages precise interface definitions

see also http://bit.ly/1ER5zVs

Page 98: Tour of language landscape
Page 99: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 100: Tour of language landscape

Homoiconicity

…homoiconicity is a property of some programming languages in which the program structure is similar to its syntax, and therefore the program’s internal representation can be

inferred by reading the text’s layout…

Page 101: Tour of language landscape

code is data data is code

Page 102: Tour of language landscape

(let [x 1] (inc x))

see also http://bit.ly/1PpIrjS

Page 103: Tour of language landscape

(let [x 1] (inc x)) !

=> 2

see also http://bit.ly/1PpIrjS

Page 104: Tour of language landscape

list (1 2 3) vector [1 2 3]

see also http://bit.ly/1PpIrjS

Page 105: Tour of language landscape

(let [x 1] (inc x)) !

list

see also http://bit.ly/1PpIrjS

Page 106: Tour of language landscape

(let [x 1] (inc x)) !

symbol

see also http://bit.ly/1PpIrjS

Page 107: Tour of language landscape

(let [x 1] (inc x)) !

vector

see also http://bit.ly/1PpIrjS

Page 108: Tour of language landscape

(let [x 1] (inc x)) !

list

see also http://bit.ly/1PpIrjS

Page 109: Tour of language landscape

form : code as data structure

see also http://bit.ly/1PpIrjS

Page 110: Tour of language landscape

code data

quote

eval

see also http://bit.ly/1PpIrjS

Page 111: Tour of language landscape

quote

(+ 1 2) => 3

see also http://bit.ly/1PpIrjS

Page 112: Tour of language landscape

quote

(+ 1 2) => 3 (quote (+ 1 2)) => (+ 1 2)

see also http://bit.ly/1PpIrjS

Page 113: Tour of language landscape

quote

(+ 1 2) => 3 (quote (+ 1 2)) => (+ 1 2) ‘(+ 1 2) => (+ 1 2)see also http://bit.ly/1PpIrjS

Page 114: Tour of language landscape

eval

‘(+ 1 2) => (+ 1 2) (eval ‘(+ 1 2)) => 3

see also http://bit.ly/1PpIrjS

Page 115: Tour of language landscape

macros

Page 116: Tour of language landscape

(defmacro assert-equals [actual expected] ‘(let [actual-val# ~actual] (when-not (= actual-val# ~expected) (throw (AssertionError. (str “FAIL in “ ‘~actual “\n expected: “ ‘~expected “\n actual: “ actual-val#))))))

see also http://bit.ly/1PpIrjS

Page 117: Tour of language landscape

(assert-equals (inc 1) 2) ; => nil (assert-equals (inc 1) (+ 0 1)) ; => AssertionError FAIL in (inc 1) ; expected: (+ 0 1) ; actual: 2

see also http://bit.ly/1PpIrjS

Page 118: Tour of language landscape

(assert-equals (inc 1) 2) ; => nil (assert-equals (inc 1) (+ 0 1)) ; => AssertionError FAIL in (inc 1) ; expected: (+ 0 1) ; actual: 2

see also http://bit.ly/1PpIrjS

Page 119: Tour of language landscape

(assert-equals (inc 1) 2) ; => nil (assert-equals (inc 1) (+ 0 1)) ; => AssertionError FAIL in (inc 1) ; expected: (+ 0 1) ; actual: 2

see also http://bit.ly/1PpIrjS

huh?? where? what? how?

Page 120: Tour of language landscape

(defmacro assert-equals [actual expected] ‘(let [actual-val# ~actual] (when-not (= actual-val# ~expected) (throw (AssertionError. (str “FAIL in “ ‘~actual “\n expected: “ ‘~expected “\n actual: “ actual-val#))))))

(assert-equals (inc 1) (+ 0 1))

see also http://bit.ly/1PpIrjS

Page 121: Tour of language landscape

(defmacro assert-equals [actual expected] ‘(let [actual-val# ~actual] (when-not (= actual-val# ~expected) (throw (AssertionError. (str “FAIL in “ ‘~actual “\n expected: “ ‘~expected “\n actual: “ actual-val#))))))

(assert-equals (inc 1) (+ 0 1))

see also http://bit.ly/1PpIrjS

Page 122: Tour of language landscape

(defmacro assert-equals [actual expected] ‘(let [actual-val# ~actual] (when-not (= actual-val# ~expected) (throw (AssertionError. (str “FAIL in “ ‘~actual “\n expected: “ ‘~expected “\n actual: “ actual-val#))))))

(assert-equals (inc 1) (+ 0 1))

see also http://bit.ly/1PpIrjS

Page 123: Tour of language landscape

see also http://bit.ly/1PpIrjS

(defmacro assert-equals [actual expected] ‘(let [actual-val# ~actual] (when-not (= actual-val# ~expected) (throw (AssertionError. (str “FAIL in “ ‘~actual “\n expected: “ ‘~expected “\n actual: “ actual-val#))))))

Page 124: Tour of language landscape

expanded at compile time

see also http://bit.ly/1PpIrjS

Page 125: Tour of language landscape

see also http://bit.ly/1PpIrjS

(macroexpand '(assert-equals (inc 1) (+ 0 1))) ; => ; (let* [actual-value__16087__auto__ (inc 1)] ; (clojure.core/when-not ; (clojure.core/= actual-value__16087__auto__ (+ 0 1)) ; (throw (java.lang.AssertionError. ; (clojure.core/str ; "FAIL in " (quote (inc 1)) ; "\nexpected: " (quote (+ 0 1)) ; "\n actual: " actual-value__16087__auto__)))))

Page 126: Tour of language landscape
Page 127: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness Types

Bit SyntaxSignals

Macros

Unit-of-Measure

Actor Model

Page 128: Tour of language landscape

GC is great

Page 129: Tour of language landscape

runtime cost

Page 130: Tour of language landscape

ownership

see also http://bit.ly/1F6WBVD

Page 131: Tour of language landscape

memory safety without GC

see also http://bit.ly/1F6WBVD

Page 132: Tour of language landscape

ZERO runtime cost

see also http://bit.ly/1F6WBVD

Page 133: Tour of language landscape

safety + speed

see also http://bit.ly/1F6WBVD

Page 134: Tour of language landscape

fn foo() { // v has ownership of the vector let v = vec![1, 2, 3]; // mutable binding let mut v2 = vec![]; } // vector is deallocated at the // end of scope, // this happens deterministically

see also http://bit.ly/1F6WBVD

Page 135: Tour of language landscape

immutable by default

see also http://bit.ly/1F6WBVD

Page 136: Tour of language landscape

// take ownership let v = vec![1, 2, 3];

see also http://bit.ly/1F6WBVD

Page 137: Tour of language landscape

// take ownership let v = vec![1, 2, 3]; !// moved ownership to v2 let v2 = v;

see also http://bit.ly/1F6WBVD

Page 138: Tour of language landscape

// take ownership let v = vec![1, 2, 3]; !// moved ownership to v2 let v2 = v; !println!("v[0] is {}", v[0]); // error: use of moved value: `v` // println!("v[0] is {}", v[0]); // ^

see also http://bit.ly/1F6WBVD

Page 139: Tour of language landscape

fn take(v : Vec<i32>) { // ownership of vector transferred // to v in this scope }

see also http://bit.ly/1F6WBVD

Page 140: Tour of language landscape

// take ownership let v = vec![1, 2, 3]; !// moved ownership take(v);

see also http://bit.ly/1F6WBVD

Page 141: Tour of language landscape

// take ownership let v = vec![1, 2, 3]; !// moved ownership take(v); !println!("v[0] is {}", v[0]); // error: use of moved value: `v` // println!("v[0] is {}", v[0]); // ^

see also http://bit.ly/1F6WBVD

Page 142: Tour of language landscape

see also http://bit.ly/1F6WBVD

Page 143: Tour of language landscape

see also http://bit.ly/1F6WBVD

let me buy your book

Page 144: Tour of language landscape

see also http://bit.ly/1F6WBVD

sure thing!

Page 145: Tour of language landscape

see also http://bit.ly/1F6WBVD

thanks

Page 146: Tour of language landscape

see also http://bit.ly/1F6WBVD

BURN!!! !>:D

Page 147: Tour of language landscape

see also http://bit.ly/1F6WBVD

but I still need it..!

:’(

Page 148: Tour of language landscape

borrowing

see also http://bit.ly/1F6WBVD

Page 149: Tour of language landscape

// note we're taking a reference, // &Vec<i32>, instead of Vec<i32> fn take(v : &Vec<i32>) { // no need to deallocate the vector // after we go out of scope here }

see also http://bit.ly/1F6WBVD

Page 150: Tour of language landscape

// take ownership let v = vec![1, 2, 3]; !// notice we're passing a reference, // &v, instead of v take(&v); // borrow ownership !println!("v[0] is {}", v[0]); // v[0] is 1

see also http://bit.ly/1F6WBVD

Page 151: Tour of language landscape

see also http://bit.ly/1F6WBVD

let me borrow your

book

Page 152: Tour of language landscape

see also http://bit.ly/1F6WBVD

sure thing!

Page 153: Tour of language landscape

see also http://bit.ly/1F6WBVD

thanks

Page 154: Tour of language landscape

see also http://bit.ly/1F6WBVD

I’m done, here you go

Page 155: Tour of language landscape

see also http://bit.ly/1F6WBVD

thanks

Page 156: Tour of language landscape

see also http://bit.ly/1F6WBVD

immutable by default

Page 157: Tour of language landscape

fn take(v : &Vec<i32>) { v.push(5); } !let v = vec![]; take(&v); // cannot borrow immutable borrowed // content `*v` as mutable // v.push(5); // ^

see also http://bit.ly/1F6WBVD

Page 158: Tour of language landscape

fn take(v : &mut Vec<i32>) { v.push(5); } !let mut v = vec![]; take(&mut v); !println!("v[0] is {}", v[0]); // v[0] is 5

see also http://bit.ly/1F6WBVD

Page 159: Tour of language landscape

borrowing rules

see also http://bit.ly/1F6WBVD

Page 160: Tour of language landscape

see also http://bit.ly/1F6WBVD

Rule 1.!!

the borrower’s scope must not outlast the owner

Page 161: Tour of language landscape

see also http://bit.ly/1F6WBVD

Rule 2.!!

one of the following, but not both:! 2.1 0 or more refs to a resource! 2.2 exactly 1 mutable ref

Page 162: Tour of language landscape

see also http://bit.ly/1F6WBVD

data race

There is a ‘data race’ when two or more pointers access the same memory location at the same time, where at least one of them is writing, and

the operations are not synchronised.

Page 163: Tour of language landscape

see also http://bit.ly/1F6WBVD

data race

a. two or more pointers to the same resource!b. at least one is writing!c. operations are not synchronised

Page 164: Tour of language landscape

see also http://bit.ly/1F6WBVD

Data Race Conditions!a. two or more pointers to the same resource!b. at least one is writing!c. operations are not synchronised

Borrowing Rules!one of the following, but not both:!

! 2.1 0 or more refs to a resource! ! 2.2 exactly 1 mutable ref

Page 165: Tour of language landscape

see also http://bit.ly/1F6WBVD

Data Race Conditions!a. two or more pointers to the same resource!b. at least one is writing!c. operations are not synchronised

Borrowing Rules!one of the following, but not both:!

! 2.1 0 or more refs to a resource! ! 2.2 exactly 1 mutable ref

Page 166: Tour of language landscape

see also http://bit.ly/1F6WBVD

Page 167: Tour of language landscape
Page 168: Tour of language landscape

Dependent Types

Uniqueness Types

Bit Syntax

Borrowed Pointers

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Signals

Macros

Unit-of-Measure

Actor Model

Page 169: Tour of language landscape

seen generics?aka parametric polymorphism

Page 170: Tour of language landscape

List<T>

Page 171: Tour of language landscape

List<T>List<int> List<Cat>

List<string>

Page 172: Tour of language landscape

what if…

Page 173: Tour of language landscape

types that depend on arbitrary values?

Page 174: Tour of language landscape

Vect n avector of n elements of type a

Page 175: Tour of language landscape

zipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c

Page 176: Tour of language landscape

zipWith f [] [] = [] zipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys

Page 177: Tour of language landscape

Type Driven Development

Page 178: Tour of language landscape

making invalid state UNREPRESENTABLE

Page 179: Tour of language landscape

see also https://vimeo.com/123606435

Page 180: Tour of language landscape
Page 181: Tour of language landscape

Signals

Dependent Types

Uniqueness Types

Bit Syntax

Borrowed Pointers

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Macros

Unit-of-Measure

Actor Model

Page 182: Tour of language landscape

Function Reactive Programming

Page 183: Tour of language landscape

Value over Time

Page 184: Tour of language landscape

Time

Value

Page 185: Tour of language landscape

Signals

Page 186: Tour of language landscape

Move Up

Move Down

Page 187: Tour of language landscape

private var arrowKeyUp:Bool; private var arrowKeyDown:Bool; !private var platform1:Platform; private var platform2:Platform; private var ball:Ball;

Page 188: Tour of language landscape

function keyDown(event:KeyboardEvent):Void { if (currentGameState == Paused && event.keyCode == 32) { setGameState(Playing); } else if (event.keyCode == 38) { ! ! arrowKeyUp = true;! }else if (event.keyCode == 40) { ! ! arrowKeyDown = true;! } }

Page 189: Tour of language landscape

function keyUp(event:KeyboardEvent):Void { if (event.keyCode == 38) { ! ! arrowKeyUp = false;! } else if (event.keyCode == 40) { ! ! arrowKeyDown = false;! } }

Page 190: Tour of language landscape

function everyFrame(event:Event):Void { if(currentGameState == Playing){ if (arrowKeyUp) { platform1.y -= platformSpeed; } if (arrowKeyDown) { platform1.y += platformSpeed; } if (platform1.y < 5) platform1.y = 5; if (platform1.y > 395) platform1.y = 395; } }

Page 191: Tour of language landscape

function everyFrame(event:Event):Void { if(currentGameState == Playing){ if (arrowKeyUp) { platform1.y -= platformSpeed; } if (arrowKeyDown) { platform1.y += platformSpeed; } if (platform1.y < 5) !! ! ! platform1.y = 5;!! ! if (platform1.y > 395) !! ! ! platform1.y = 395;! } }

Page 192: Tour of language landscape

source files

state changes

Page 193: Tour of language landscape

source files execution

Page 194: Tour of language landscape

source files execution

Page 195: Tour of language landscape

mental model

input state new state behaviour

{ x; y } { x; y-speed }

{ x; y } { x; y+speed }

timer { x; y } { x; y } draw platform

… … … …

Page 196: Tour of language landscape

transformation

let y = f(x)

Imperative Functional

x.f()

mutation

Page 197: Tour of language landscape

transformations simplify problem

decomposition

Page 198: Tour of language landscape

Move Up

Move Down

Page 199: Tour of language landscape

type alias Platform = {x:Int, y:Int} defaultPlatform = {x=5, y=0} !delta = Time.fps 20 input = Signal.sampleOn delta Keyboard.arrows !cap x = max 5 <| min x 395 !p1 : Signal Platform p1 = foldp (\{x, y} s -> {s | y <- cap <| s.y + 5*y}) defaultPlatform input

Page 200: Tour of language landscape

type alias Platform = {x:Int, y:Int}!defaultPlatform = {x=5, y=0} !delta = Time.fps 20 input = Signal.sampleOn delta Keyboard.arrows !cap x = max 5 <| min x 395 !p1 : Signal Platform p1 = foldp (\{x, y} s -> {s | y <- cap <| s.y + 5*y}) defaultPlatform input

Page 201: Tour of language landscape

type alias Platform = {x:Int, y:Int} defaultPlatform = {x=5, y=0} !delta = Time.fps 20 input = Signal.sampleOn delta Keyboard.arrows !cap x = max 5 <| min x 395 !p1 : Signal Platform p1 = foldp (\{x, y} s -> {s | y <- cap <| s.y + 5*y}) defaultPlatform input

Page 202: Tour of language landscape

Keyboard.arrowsUP { x=0, y=1 } DOWN { x=0, y=-1 } LEFT { x=-1, y=0 } RIGHT { x=1, y=0 }

Page 203: Tour of language landscape

type alias Platform = {x:Int, y:Int} defaultPlatform = {x=5, y=0} !delta = Time.fps 20 input = Signal.sampleOn delta Keyboard.arrows !cap x = max 5 <| min x 395 !p1 : Signal Platform!p1 = foldp (\{x, y} s -> {s | y <- cap <| s.y + 5*y}) defaultPlatform input

Page 204: Tour of language landscape

type alias Platform = {x:Int, y:Int} defaultPlatform = {x=5, y=0} !delta = Time.fps 20 input = Signal.sampleOn delta Keyboard.arrows !cap x = max 5 <| min x 395 !p1 : Signal Platform p1 = foldp (\{x, y} s -> {s | y <- cap <| s.y + 5*y}) defaultPlatform input

Page 205: Tour of language landscape

type alias Platform = {x:Int, y:Int} defaultPlatform = {x=5, y=0} !delta = Time.fps 20 input = Signal.sampleOn delta Keyboard.arrows !cap x = max 5 <| min x 395 !p1 : Signal Platform p1 = foldp (\{x, y} s -> {s | y <- cap <| s.y + 5*y}) defaultPlatform input

Page 206: Tour of language landscape

type alias Platform = {x:Int, y:Int} defaultPlatform = {x=5, y=0} !delta = Time.fps 20 input = Signal.sampleOn delta Keyboard.arrows !cap x = max 5 <| min x 395 !p1 : Signal Platform p1 = foldp (\{x, y} s -> {s | y <- cap <| s.y + 5*y}) defaultPlatform input

Page 207: Tour of language landscape

“I thought of objects being like biological cells and/or

individual computers on a network, only able to

communicate with messages.”

- Alan Kay

Page 208: Tour of language landscape

“OOP to me means only messaging, local retention and protection and hiding of state-

process, and extreme late-binding of all things.”

- Alan Kay

Page 209: Tour of language landscape
Page 210: Tour of language landscape

Borrowed Pointers

Actor Model

Bit Syntax

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Dependent Types

Uniqueness Types

Signals

Macros

Unit-of-Measure

Page 211: Tour of language landscape

actor model

Page 212: Tour of language landscape

actor

state mailbox

Page 213: Tour of language landscape

actors share nothing

Page 214: Tour of language landscape

actor

state mailboxactor

Page 215: Tour of language landscape

actor

state mailboxactor

Page 216: Tour of language landscape

processing!storage!

communication

Page 217: Tour of language landscape

loop (Map) ->! receive! {get, Key, Pid} ->! Pid ! maps:get(Key, Map, not_found),! loop(Map);! {set, Key, Value} ->! loop(maps:put(Key, Value, Map))! end.

Page 218: Tour of language landscape

loop (Map) ->! receive! {get, Key, Pid} ->! Pid ! maps:get(Key, Map, not_found),! loop(Map);! {set, Key, Value} ->! loop(maps:put(Key, Value, Map))! end.

Page 219: Tour of language landscape

loop (Map) ->! receive! {get, Key, Pid} ->! Pid ! maps:get(Key, Map, not_found),! loop(Map);! {set, Key, Value} ->! loop(maps:put(Key, Value, Map))! end.

Page 220: Tour of language landscape

loop (Map) ->! receive! {get, Key, Pid} ->! Pid ! maps:get(Key, Map, not_found),! loop(Map);! {set, Key, Value} ->! loop(maps:put(Key, Value, Map))! end.

Page 221: Tour of language landscape

client (N, Pid) ->! Pid ! {set, N, N},! Pid ! {get, N, self()},! receive! not_found -> io:format(“~p :-(~n”, [N]);! N -> io:format(“~p :-)~n”, [N]);! _ -> io:format(“~p …~n”, [N])! end.

Page 222: Tour of language landscape

client (N, Pid) ->! Pid ! {set, N, N},! Pid ! {get, N, self()},! receive! not_found -> io:format(“~p :-(~n”, [N]);! N -> io:format(“~p :-)~n”, [N]);! _ -> io:format(“~p …~n”, [N])! end.

Page 223: Tour of language landscape

client (N, Pid) ->! Pid ! {set, N, N},! Pid ! {get, N, self()},! receive! not_found -> io:format(“~p :-(~n”, [N]);! N -> io:format(“~p :-)~n”, [N]);! _ -> io:format(“~p …~n”, [N])! end.

Page 224: Tour of language landscape

start(N) ->! Kvs = spawn(mod, loop, [#{}]),! [spawn(mod, client, [X, Kvs]) ! || X <- lists:seq(1,N)].

Page 225: Tour of language landscape
Page 226: Tour of language landscape

actors are cheap

Page 227: Tour of language landscape

no locks!

Page 228: Tour of language landscape

need state?!talk to the actor!

Page 229: Tour of language landscape

location transparency

Page 230: Tour of language landscape

pre-emptive scheduling

Page 231: Tour of language landscape

makes you !THINK !

about !distributed systems

Page 232: Tour of language landscape

messaging promotes failure thinking

Page 233: Tour of language landscape

Distributed

Computing

Page 234: Tour of language landscape

Network is reliable!Latency is zero!

Bandwidth is infinite!Network is secure!

Topology doesn't change!There is one administrator!

Transport cost is zero!The network is homogeneous

8 fallacies of distributed computing

Page 235: Tour of language landscape

supervise & restart

Page 236: Tour of language landscape
Page 237: Tour of language landscape

http://www.ustream.tv/recorded/61443262

https://aphyr.com/posts

Page 238: Tour of language landscape

Borrowed Pointers

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Dependent Types

Uniqueness Types

Signals

Macros

Unit-of-Measure

Bit Syntax

Actor Model

Page 239: Tour of language landscape

pattern matching

Page 240: Tour of language landscape

{ X, Y } = { 1, 2 }

Page 241: Tour of language landscape

{ X, Y } = { 1, 2 }

Page 242: Tour of language landscape

[ H | T ] = [ 1, 2, 3 ]

Page 243: Tour of language landscape

image from http://learnyousomeerlang.com/

Page 244: Tour of language landscape

[ H | T ] = [ 1, 2, 3 ]

Page 245: Tour of language landscape

what if…

Page 246: Tour of language landscape

you can pattern match binary data?!e.g. TCP payload

Page 247: Tour of language landscape
Page 248: Tour of language landscape

<<SourcePort:16, DestinationPort:16, ! SeqNumber:32,! AckNumber:32, DataOffset:4, ! Reserved:3, Flags:9, WindSize:16,! CheckSum:16, UrgentPointer:16,! Payload/binary>> = SomeBinary

Page 249: Tour of language landscape
Page 250: Tour of language landscape

<<SourcePort:16, DestinationPort:16, ! SeqNumber:32,! AckNumber:32, DataOffset:4, ! Reserved:3, Flags:9, WindSize:16,! CheckSum:16, UrgentPointer:16,! Payload/binary>> = SomeBinary

Page 251: Tour of language landscape

<<SourcePort:16, DestinationPort:16, ! SeqNumber:32,! AckNumber:32, DataOffset:4, ! Reserved:3, Flags:9, WindSize:16,! CheckSum:16, UrgentPointer:16,! Payload/binary>> = SomeBinary

Page 252: Tour of language landscape

<<SourcePort:16, DestinationPort:16, ! SeqNumber:32,! AckNumber:32, DataOffset:4, ! Reserved:3, Flags:9, WindSize:16,! CheckSum:16, UrgentPointer:16,! Payload/binary>> = SomeBinary

Page 253: Tour of language landscape
Page 254: Tour of language landscape

<<SourcePort:16, DestinationPort:16, ! SeqNumber:32,! AckNumber:32, DataOffset:4, ! Reserved:3, Flags:9, WindSize:16,! CheckSum:16, UrgentPointer:16,! Payload/binary>> = SomeBinary

Page 255: Tour of language landscape

.!

.!

.

Page 256: Tour of language landscape

<<SourcePort:16, DestinationPort:16, ! SeqNumber:32,! AckNumber:32, DataOffset:4, ! Reserved:3, Flags:9, WindSize:16,! CheckSum:16, UrgentPointer:16,! Payload/binary>> = SomeBinary

Page 257: Tour of language landscape

case Packet of! <<SeqNum:16/big-unsigned-integer, ! Timestamp:32/big-unsigned-integer, ! Src:32/little-signed-integer, ! _/binary>> ->!! % do something useful!! …! _ ->!! % invalid format!! …!end

Page 258: Tour of language landscape

case Packet of! <<SeqNum:16/big-unsigned-integer, ! Timestamp:32/big-unsigned-integer, ! Src:32/little-signed-integer, ! _/binary>> ->!! % do something useful!! …! _ ->!! % invalid format!! …!end

Page 259: Tour of language landscape

case Packet of! <<SeqNum:16/big-unsigned-integer, ! Timestamp:32/big-unsigned-integer, ! Src:32/little-signed-integer, ! _/binary>> ->!! % do something useful!! …! _ ->!! % invalid format!! …!end

Page 260: Tour of language landscape

case Packet of! <<SeqNum:16/big-unsigned-integer, ! Timestamp:32/big-unsigned-integer, ! Src:32/little-signed-integer, ! _/binary>> ->!! % do something useful!! …! _ ->!! % invalid format!! …!end

Page 261: Tour of language landscape

case Packet of! <<SeqNum:16/big-unsigned-integer, ! Timestamp:32/big-unsigned-integer, ! Src:32/little-signed-integer, ! _/binary>> ->!! % do something useful!! …! _ ->!! % invalid format!! …!end

Page 262: Tour of language landscape

Type Provider Pipes

Statically Resolved TP Implicit Interface Implementation

Borrowed Pointers Dependent Types

Uniqueness TypesOTP

Bit SyntaxSignals

Macros

Unit-of-Measure

Page 263: Tour of language landscape

10,000 hours to be good at something

see also http://bit.ly/1KN7SLq

Page 264: Tour of language landscape

10,000 hours to be good at something

see also http://bit.ly/1KN7SLq

Page 265: Tour of language landscape

10,000 hours to reach top of an ultra-

competitive field

see also http://bit.ly/1KN7SLq

Page 266: Tour of language landscape
Page 267: Tour of language landscape

the first 20 hours - how to learn anything

see also http://bit.ly/1KN7SLq

Page 268: Tour of language landscape

Practice Time

How

goo

d yo

u ar

e

see also http://bit.ly/1KN7SLq

Page 269: Tour of language landscape

1.Deconstruct the skill

see also http://bit.ly/1KN7SLq

Page 270: Tour of language landscape

1.Deconstruct the skill!2.Learn enough to self-correct

see also http://bit.ly/1KN7SLq

Page 271: Tour of language landscape

1.Deconstruct the skill!2.Learn enough to self-correct!3.Remove practice barriers

see also http://bit.ly/1KN7SLq

Page 272: Tour of language landscape

1.Deconstruct the skill!2.Learn enough to self-correct!3.Remove practice barriers!4.Practice at least 20 hrs

see also http://bit.ly/1KN7SLq

Page 273: Tour of language landscape
Page 274: Tour of language landscape

learn a new paradigm!not a new syntax

see also http://bit.ly/1IzXVSo

Page 275: Tour of language landscape

logic programming

Page 276: Tour of language landscape

stack-oriented programming

Page 277: Tour of language landscape

array programming

Page 278: Tour of language landscape

“A language that doesn't affect the way you think

about programming, is not worth knowing.”

- Alan Perlis

Page 279: Tour of language landscape

see also http://bit.ly/1IzXVSo

Page 280: Tour of language landscape

see also http://bit.ly/1IzXVSo

Page 281: Tour of language landscape

Enterprise Tic-Tac-Toe - a Functional Approach

Type Driven Development

Computation expression in context : a history of the otter king

Learning From Haskell

Page 282: Tour of language landscape

“Learning is an act of creation itself, because something happens in you that wasn't

there before.”

- Alan Kay

Page 283: Tour of language landscape

@theburningmonktheburningmonk.comgithub.com/theburningmonk

Page 284: Tour of language landscape

@theburningmonktheburningmonk.comgithub.com/theburningmonk

Page 285: Tour of language landscape

WE’RE HIRINGwww.gamesyscorporate.com/careers


Recommended