SlideShare a Scribd company logo
1 of 190
Download to read offline
Yan Cui
!
Talk title: My Adventure with Elm
!
theburningmonk@gmail.com - GameSys - @theburningmonk
ROME 27-28 march 2015
ROME 27-28 march 2015 – Yan Cui @theburningmonk
agenda
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Hi, my name isYan Cui.
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
I’m not an expert on Elm.
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Function Reactive
Programming?
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Value over Time
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Time
Value
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Time
Value
Signal
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Reactive is Dead,	

long live composing side effects.
bit.ly/1sb5hCu
ROME 27-28 march 2015 – Yan Cui @theburningmonk
β€œOne thing I’m discovering is
that transforming data is
easier to think about than
maintaining state.”	

!
	

 	

 - Dave Thomas
ROME 27-28 march 2015 – Yan Cui @theburningmonk
let y = f(x)
Imperative Functional
x.f()
ROME 27-28 march 2015 – Yan Cui @theburningmonk
mutation
let y = f(x)
Imperative Functional
x.f()
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Move Up
Move Down
ROME 27-28 march 2015 – Yan Cui @theburningmonk
private var arrowKeyUp:Bool;	

private var arrowKeyDown:Bool;	

!
private var platform1:Platform;	

private var platform2:Platform;	

private var ball:Ball;
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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;
	

 }	

}
ROME 27-28 march 2015 – Yan Cui @theburningmonk
function keyUp(event:KeyboardEvent):Void {	

	

 if (event.keyCode == 38) {	

arrowKeyUp = false;
	

 } else if (event.keyCode == 40) {	

arrowKeyDown = false;
	

 }	

}
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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;	

	

 }	

}
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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;
	

 }	

}
ROME 27-28 march 2015 – Yan Cui @theburningmonk
source files
state changes
ROME 27-28 march 2015 – Yan Cui @theburningmonk
source files execution
ROME 27-28 march 2015 – Yan Cui @theburningmonk
source files execution
ROME 27-28 march 2015 – Yan Cui @theburningmonk
mental model
input state new state behaviour
{ x; y } { x; y-speed }
{ x; y } { x; y+speed }
timer { x; y } { x; y } draw platform
… … … …
ROME 27-28 march 2015 – Yan Cui @theburningmonk
transformation
let y = f(x)
Imperative Functional
x.f()
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Transformations
simplify problem
decomposition
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Move Up
Move Down
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
UP	

 	

 	

 { x=0, y=1 }	

DOWN	

	

 { x=0, y=-1 }	

LEFT	

	

 	

 { x=-1, y=0 }	

RIGHT	

 	

 { x=1, y=0 }
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
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
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Rx Dart Elm
Observable Stream Signal
= =
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Idea See in Action
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Yan Cui
!
Talk title: My Adventure with Elm
!
theburningmonk@gmail.com - GameSys - @theburningmonk
ROME 27-28 march 2015
ROME 27-28 march 2015 – Yan Cui @theburningmonk
http://bit.ly/1wV46XS
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Elm Basics
ROME 27-28 march 2015 – Yan Cui @theburningmonk
add x y = x + y
ROME 27-28 march 2015 – Yan Cui @theburningmonk
add : Int -> Int -> Int
add x y = x + y
ROME 27-28 march 2015 – Yan Cui @theburningmonk
calcAngle start end =	

	

 let	

distH	

 = end.x - start.x	

	

	

 distV 	

= end.y - start.y	

	

 in atan2 distV distH
ROME 27-28 march 2015 – Yan Cui @theburningmonk
calcAngle start end =	

	

 let	

distH	

 = end.x - start.x	

	

	

 distV 	

= end.y - start.y	

	

 in atan2 distV distH
ROME 27-28 march 2015 – Yan Cui @theburningmonk
calcAngle start end =	

	

 let	

distH	

 = end.x - start.x	

	

	

 distV 	

= end.y - start.y	

	

 in atan2 distV distH
ROME 27-28 march 2015 – Yan Cui @theburningmonk
multiply x y	

= x * y	

triple = multiply 3
ROME 27-28 march 2015 – Yan Cui @theburningmonk
multiply x y	

= x * y	

triple = multiply 3
ROME 27-28 march 2015 – Yan Cui @theburningmonk
f a b c d = …	

f :	

 Int -> 	

	

 	

 	

 (Int -> 	

	

 	

 	

 	

 (Int -> 	

	

 	

 	

 	

 	

 (Int -> Int)))
ROME 27-28 march 2015 – Yan Cui @theburningmonk
double list = List.map (x -> x * 2) list
ROME 27-28 march 2015 – Yan Cui @theburningmonk
double list = List.map ((*) 2) list
ROME 27-28 march 2015 – Yan Cui @theburningmonk
tuple1 = (2,β€œthree”)	

tuple2 = (2,β€œthree”, [4, 5])
ROME 27-28 march 2015 – Yan Cui @theburningmonk
tuple4 = (,) 2 β€œthree”	

tuple5 = (,,) 2 β€œthree” [4, 5]
ROME 27-28 march 2015 – Yan Cui @theburningmonk
x = { age=42, name=β€œfoo” }
ROME 27-28 march 2015 – Yan Cui @theburningmonk
lightweight, labelled
data structure
ROME 27-28 march 2015 – Yan Cui @theburningmonk
x.age	

x.name
-- 42	

-- β€œfoo”
ROME 27-28 march 2015 – Yan Cui @theburningmonk
x.age	

x.name
-- 42	

-- β€œfoo”
.age x	

.name x
-- 42	

-- β€œfoo”
ROME 27-28 march 2015 – Yan Cui @theburningmonk
-- clone and update	

y = { x | name <- "bar" }
ROME 27-28 march 2015 – Yan Cui @theburningmonk
type alias Character = 	

{ age : Int, name : String }
ROME 27-28 march 2015 – Yan Cui @theburningmonk
type alias Named a = { a | name : String }	

type alias Aged a = { a | age : Int }
ROME 27-28 march 2015 – Yan Cui @theburningmonk
lady : Named ( Aged { } )	

lady = { name=β€œfoo”, age=42 }
ROME 27-28 march 2015 – Yan Cui @theburningmonk
getName : Named x -> String	

getName { name } = name
ROME 27-28 march 2015 – Yan Cui @theburningmonk
getName : Named x -> String	

getName { name } = name	

!
getName lady	

	

 -- β€œfoo”
ROME 27-28 march 2015 – Yan Cui @theburningmonk
type Status = Flying Pos Speed	

	

 	

 	

 	

 	

 	

 	

 | Exploding Radius	

	

 	

 	

 	

 	

 	

 	

 | Exploded
ROME 27-28 march 2015 – Yan Cui @theburningmonk
aka.	

β€œsums-and-products”	

data structures
ROME 27-28 march 2015 – Yan Cui @theburningmonk
type Status = Flying Pos Speed	

	

 	

 	

 	

 	

 	

 | Exploding Radius	

	

 	

 	

 	

 	

 	

 | Exploded
sums : 	

choice between variants of a type
ROME 27-28 march 2015 – Yan Cui @theburningmonk
products : 	

tuple of types
type Status = Flying Pos Speed	

	

 	

 	

 	

 	

 	

 | Exploding Radius	

	

 	

 	

 	

 	

 	

 | Exploded
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y radius =	

	

 circle radius	

	

|> filled (rgb 150 170 150)	

	

 |> alpha 0.5	

	

 |> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y radius =	

	

 circle radius	

	

|> filled (rgb 150 170 150)	

	

 |> alpha 0.5	

	

 |> move (x, y)	

filled : Color -> Shape -> Form
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y radius =	

	

 circle radius	

	

|> filled (rgb 150 170 150)	

	

 |> alpha 0.5	

	

 |> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y radius =	

	

 circle radius	

	

|> filled (rgb 150 170 150)	

	

 |> alpha 0.5	

	

 |> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
β€œβ€¦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)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y radius =	

	

 radius |> circle	

	

|> filled (rgb 150 170 150)	

	

 |> alpha 0.5	

	

 |> move (x, y)	

2.top-to-bottom
1. left-to-right
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle : Int -> Int -> Float -> Form
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 circle 	

	

>> filled (rgb 150 170 150)	

	

>> alpha 0.5	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 circle 	

	

>> filled (rgb 150 170 150)	

	

>> alpha 0.5	

	

>> move (x, y)
circle : Float -> Shape
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> filled (rgb 150 170 150)	

	

>> alpha 0.5	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> filled (rgb 150 170 150)	

	

>> alpha 0.5	

	

>> move (x, y)
filled : Color -> Shape -> Form
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> filled (rgb 150 170 150)	

	

>> alpha 0.5	

	

>> move (x, y)
Curried!
filled : Color -> Shape -> Form
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> filled (rgb 150 170 150)	

	

>> alpha 0.5	

	

>> move (x, y)
Shape -> Form
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> (Shape -> Form)	

	

>> alpha 0.5	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> (Shape -> Form) 	

	

>> alpha 0.5	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> (Shape -> Form) 	

	

>> alpha 0.5	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Shape) 	

	

>> (Shape -> Form) 	

	

>> alpha 0.5	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Form)	

	

>> alpha 0.5	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Form)	

	

>> (Form -> Form)	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Form)	

	

>> (Form -> Form)	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Form)	

	

>> move (x, y)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Form)	

	

>> (Form -> Form)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Form)	

	

>> (Form -> Form)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle x y =	

	

 (Float -> Form)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
drawCircle : Int -> Int -> (Float -> Form)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
greet name =	

case name of 	

"Yan" 	

-> β€œhi, theburningmonk"	

_ 	

	

 -> β€œhi,β€œ ++ name
ROME 27-28 march 2015 – Yan Cui @theburningmonk
greet name =	

case name of 	

"Yan" 	

-> β€œhi, theburningmonk"	

_ 	

	

 -> β€œhi,β€œ ++ name
ROME 27-28 march 2015 – Yan Cui @theburningmonk
fizzbuzz n =	

if | n % 15 == 0	

-> "fizz buzz"	

| n % 3 	

== 0	

-> "fizz"	

| n % 5 	

== 0	

-> "buzz"	

| otherwise 	

-> show n
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Mouse.position	

Mouse.clicks	

Mouse.isDown	

…
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Window.dimension	

Window.width	

Window.height
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Time.every	

Time.fps	

Time.timestamp	

Time.delay	

…
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Mouse.position : Signal (Int, Int)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Mouse.position : Signal (Int, Int)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Mouse.position : Signal (Int, Int)
(10, 23) (3, 16) (8, 10) (12, 5) (18, 3)
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Keyboard.lastPressed : Signal Int
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Keyboard.lastPressed : Signal Int
H E L L O space
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Keyboard.lastPressed : Signal Int
H E L L O space
72 69 76 76 79 32
ROME 27-28 march 2015 – Yan Cui @theburningmonk
map : (a -> b) -> Signal a -> Signal b
ROME 27-28 march 2015 – Yan Cui @theburningmonk
<~
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Signal of num of pixels in window
ROME 27-28 march 2015 – Yan Cui @theburningmonk
((w, h) -> w*h) <~ Window.dimensions
ROME 27-28 march 2015 – Yan Cui @theburningmonk
((w, h) -> w*h) <~ Window.dimensions
Signal (Int, Int)(Int, Int) -> Int
ROME 27-28 march 2015 – Yan Cui @theburningmonk
((w, h) -> w*h) <~ Window.dimensions
Signal (Int, Int)(Int, Int) -> Int
Signal Int
ROME 27-28 march 2015 – Yan Cui @theburningmonk
(10, 10) (15, 10) (18, 12)
100 150 216
((w, h) -> w*h) <~ Window.dimensions
ROME 27-28 march 2015 – Yan Cui @theburningmonk
map2 : (a -> b -> c) 	

	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b 	

	

 	

 	

 	

 -> Signal c
ROME 27-28 march 2015 – Yan Cui @theburningmonk
~
ROME 27-28 march 2015 – Yan Cui @theburningmonk
(,) <~ Window.width ~ Window.height
Signal Int
a -> b -> (a, b)
Signal Int
ROME 27-28 march 2015 – Yan Cui @theburningmonk
(,) <~ Window.width ~ Window.height
Signal Int
Int -> Int -> (Int, Int)
Signal Int
ROME 27-28 march 2015 – Yan Cui @theburningmonk
map3 : (a -> b -> c -> d) 	

	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b 	

	

 	

 	

 	

 -> Signal c	

	

 	

 	

 	

 -> Signal d
ROME 27-28 march 2015 – Yan Cui @theburningmonk
(,,) <~ signalA ~ signalB ~ signalC
ROME 27-28 march 2015 – Yan Cui @theburningmonk
map4 : …	

map5 : …	

map6 : …	

map7 : …	

map8 : …
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp : (a -> b -> b) 	

	

 	

 	

 	

 -> b 	

	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp : (a -> b -> b) 	

	

 	

 	

 	

 -> b
	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp : (a -> b -> b) 	

	

 	

 	

 	

 -> b
	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp : (a -> b -> b) 	

	

 	

 	

 -> b 	

	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp : (a -> b -> b) 	

	

 	

 	

 	

 -> b 	

	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp : (a -> b -> b) 	

	

 	

 	

 	

 -> b 	

	

 	

 	

 	

 -> Signal a 	

	

 	

 	

 	

 -> Signal b
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp (_ n -> n + 1) 0 Mouse.clicks
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp (_ n -> n + 1) 0 Mouse.clicks
ROME 27-28 march 2015 – Yan Cui @theburningmonk
foldp (_ n -> n + 1) 0 Mouse.clicks
ROME 27-28 march 2015 – Yan Cui @theburningmonk
1 3 42 5
foldp (_ n -> n + 1) 0 Mouse.clicks
ROME 27-28 march 2015 – Yan Cui @theburningmonk
UP	

	

 	

 	

 { x=0, y=1 }	

DOWN	

 { x=0, y=-1 }	

LEFT	

	

 	

 { x=-1, y=0 }	

RIGHT	

	

 { x=1, y=0 }
ROME 27-28 march 2015 – Yan Cui @theburningmonk
merge	

 : Signal a -> Signal a -> Signal a	

mergeMany : List (Signal a) -> Signal a	

…
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Js Interop,
WebGL
HTML layout,
dependency management,
etc.
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
8 segments
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
ROME 27-28 march 2015 – Yan Cui @theburningmonk
change
change
no changenot allowed
direction
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
cherry
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
YUMYUMYUM!
ROME 27-28 march 2015 – Yan Cui @theburningmonk
direction
+1 segment
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Demo
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
github.com/theburningmonk/elm-snake
github.com/theburningmonk/elm-missile-
command
Missile Command
Snake
ROME 27-28 march 2015 – Yan Cui @theburningmonk
elm-lang.org/try
debug.elm-lang.org/try
ROME 27-28 march 2015 – Yan Cui @theburningmonk
the
Β not
Β so
Β great
Β things
ROME 27-28 march 2015 – Yan Cui @theburningmonk
Type error between lines 63 and 85:	

case gameState of	

NotStarted - if | userInput == Space -	

Started (defaultSnake,Nothing)	

| True - gameState	

Started ({segments,direction},cherry) - let arrow = case userInput	

of	

Arrow arrow - arrow	

_ - {x = 0, y = 0}	

newDirection = getNewDirection	

arrow direction	

newHead = getNewSegment	

(List.head segments) newDirection	

newTail = List.take	

((List.length segments) - 1)	

segments	

(w,h) = windowDims	

isGameOver = (List.any	

(t - t == newHead)	

newTail) ||	

(((fst newHead) 	

((toFloat w) / 2)) ||	

(((snd newHead) 	

((toFloat h) / 2)) ||	

(((fst newHead) 	

((toFloat (-w)) / 2)) ||	

((snd newHead) 	

((toFloat (-h)) / 2)))))	

in if | isGameOver - NotStarted	

| True -	

Started	

({segments = newHead :: newTail,	

direction = newDirection},	

cherry)	

!
Expected Type: {}	

Actual Type: Snake.Input
cryptic error
messages
ROME 27-28 march 2015 – Yan Cui @theburningmonk
breaking changes
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk
ROME 27-28 march 2015 – Yan Cui @theburningmonk

More Related Content

More from Codemotion

Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Codemotion
Β 
Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019Codemotion
Β 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Codemotion
Β 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 - Codemotion
Β 
Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Codemotion
Β 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Codemotion
Β 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Codemotion
Β 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Codemotion
Β 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Codemotion
Β 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Codemotion
Β 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Codemotion
Β 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...Codemotion
Β 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Codemotion
Β 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Codemotion
Β 
Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019Codemotion
Β 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Codemotion
Β 
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...Codemotion
Β 
Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019
Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019
Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019Codemotion
Β 
Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019
Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019
Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019Codemotion
Β 
Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019
Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019
Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019Codemotion
Β 

More from Codemotion (20)

Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Β 
Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard SΓΌselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Β 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Β 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Β 
Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin FΓΆrtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Β 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Β 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Β 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Β 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Β 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Β 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Β 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Β 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Β 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Β 
Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back β€œSoftware Engineering” - Codemotion Amsterdam 2019
Β 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Β 
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Β 
Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019
Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019
Mete Atamel - Serverless with Knative - Codemotion Amsterdam 2019
Β 
Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019
Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019
Rahul Shetty - Corporate relocation prediction - Codemotion Amsterdam 2019
Β 
Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019
Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019
Mario Viviani - Designing apps for fire TV - Codemotion Amsterdam 2019
Β 

Recently uploaded

XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
Β 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
Β 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
Β 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
Β 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
Β 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
Β 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
Β 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
Β 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
Β 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
Β 
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”soniya singh
Β 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
Β 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
Β 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
Β 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
Β 
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...soniya singh
Β 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
Β 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
Β 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
Β 

Recently uploaded (20)

XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
Β 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Β 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
Β 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
Β 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
Β 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
Β 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
Β 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
Β 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Β 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Β 
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Β 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
Β 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
Β 
Call Girls In Mukherjee Nagar πŸ“± 9999965857 🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar πŸ“±  9999965857  🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar πŸ“±  9999965857  🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar πŸ“± 9999965857 🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Β 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
Β 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
Β 
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Β 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Β 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
Β 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
Β 

My adventure with Elm - Yan Cui - Codemotion Roma 2015

  • 1. Yan Cui ! Talk title: My Adventure with Elm ! theburningmonk@gmail.com - GameSys - @theburningmonk ROME 27-28 march 2015
  • 2. ROME 27-28 march 2015 – Yan Cui @theburningmonk agenda
  • 3. ROME 27-28 march 2015 – Yan Cui @theburningmonk Hi, my name isYan Cui.
  • 4. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 5. ROME 27-28 march 2015 – Yan Cui @theburningmonk I’m not an expert on Elm.
  • 6. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 7. ROME 27-28 march 2015 – Yan Cui @theburningmonk Function Reactive Programming?
  • 8. ROME 27-28 march 2015 – Yan Cui @theburningmonk Value over Time
  • 9. ROME 27-28 march 2015 – Yan Cui @theburningmonk Time Value
  • 10. ROME 27-28 march 2015 – Yan Cui @theburningmonk Time Value Signal
  • 11. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 12. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 13. ROME 27-28 march 2015 – Yan Cui @theburningmonk Reactive is Dead, long live composing side effects. bit.ly/1sb5hCu
  • 14. ROME 27-28 march 2015 – Yan Cui @theburningmonk β€œOne thing I’m discovering is that transforming data is easier to think about than maintaining state.” ! - Dave Thomas
  • 15. ROME 27-28 march 2015 – Yan Cui @theburningmonk let y = f(x) Imperative Functional x.f()
  • 16. ROME 27-28 march 2015 – Yan Cui @theburningmonk mutation let y = f(x) Imperative Functional x.f()
  • 17. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 18. ROME 27-28 march 2015 – Yan Cui @theburningmonk Move Up Move Down
  • 19. ROME 27-28 march 2015 – Yan Cui @theburningmonk private var arrowKeyUp:Bool; private var arrowKeyDown:Bool; ! private var platform1:Platform; private var platform2:Platform; private var ball:Ball;
  • 20. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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; } }
  • 21. ROME 27-28 march 2015 – Yan Cui @theburningmonk function keyUp(event:KeyboardEvent):Void { if (event.keyCode == 38) { arrowKeyUp = false; } else if (event.keyCode == 40) { arrowKeyDown = false; } }
  • 22. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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; } }
  • 23. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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; } }
  • 24. ROME 27-28 march 2015 – Yan Cui @theburningmonk source files state changes
  • 25. ROME 27-28 march 2015 – Yan Cui @theburningmonk source files execution
  • 26. ROME 27-28 march 2015 – Yan Cui @theburningmonk source files execution
  • 27. ROME 27-28 march 2015 – Yan Cui @theburningmonk mental model input state new state behaviour { x; y } { x; y-speed } { x; y } { x; y+speed } timer { x; y } { x; y } draw platform … … … …
  • 28. ROME 27-28 march 2015 – Yan Cui @theburningmonk transformation let y = f(x) Imperative Functional x.f()
  • 29. ROME 27-28 march 2015 – Yan Cui @theburningmonk Transformations simplify problem decomposition
  • 30. ROME 27-28 march 2015 – Yan Cui @theburningmonk Move Up Move Down
  • 31. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 32. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 33. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 34. ROME 27-28 march 2015 – Yan Cui @theburningmonk UP { x=0, y=1 } DOWN { x=0, y=-1 } LEFT { x=-1, y=0 } RIGHT { x=1, y=0 }
  • 35. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 36. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 37. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 38. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 39. ROME 27-28 march 2015 – Yan Cui @theburningmonk 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
  • 40. ROME 27-28 march 2015 – Yan Cui @theburningmonk Rx Dart Elm Observable Stream Signal = =
  • 41. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 42. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 43. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 44. ROME 27-28 march 2015 – Yan Cui @theburningmonk Idea See in Action
  • 45. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 46. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 47. Yan Cui ! Talk title: My Adventure with Elm ! theburningmonk@gmail.com - GameSys - @theburningmonk ROME 27-28 march 2015
  • 48. ROME 27-28 march 2015 – Yan Cui @theburningmonk http://bit.ly/1wV46XS
  • 49. ROME 27-28 march 2015 – Yan Cui @theburningmonk Elm Basics
  • 50. ROME 27-28 march 2015 – Yan Cui @theburningmonk add x y = x + y
  • 51. ROME 27-28 march 2015 – Yan Cui @theburningmonk add : Int -> Int -> Int add x y = x + y
  • 52. ROME 27-28 march 2015 – Yan Cui @theburningmonk calcAngle start end = let distH = end.x - start.x distV = end.y - start.y in atan2 distV distH
  • 53. ROME 27-28 march 2015 – Yan Cui @theburningmonk calcAngle start end = let distH = end.x - start.x distV = end.y - start.y in atan2 distV distH
  • 54. ROME 27-28 march 2015 – Yan Cui @theburningmonk calcAngle start end = let distH = end.x - start.x distV = end.y - start.y in atan2 distV distH
  • 55. ROME 27-28 march 2015 – Yan Cui @theburningmonk multiply x y = x * y triple = multiply 3
  • 56. ROME 27-28 march 2015 – Yan Cui @theburningmonk multiply x y = x * y triple = multiply 3
  • 57. ROME 27-28 march 2015 – Yan Cui @theburningmonk f a b c d = … f : Int -> (Int -> (Int -> (Int -> Int)))
  • 58. ROME 27-28 march 2015 – Yan Cui @theburningmonk double list = List.map (x -> x * 2) list
  • 59. ROME 27-28 march 2015 – Yan Cui @theburningmonk double list = List.map ((*) 2) list
  • 60. ROME 27-28 march 2015 – Yan Cui @theburningmonk tuple1 = (2,β€œthree”) tuple2 = (2,β€œthree”, [4, 5])
  • 61. ROME 27-28 march 2015 – Yan Cui @theburningmonk tuple4 = (,) 2 β€œthree” tuple5 = (,,) 2 β€œthree” [4, 5]
  • 62. ROME 27-28 march 2015 – Yan Cui @theburningmonk x = { age=42, name=β€œfoo” }
  • 63. ROME 27-28 march 2015 – Yan Cui @theburningmonk lightweight, labelled data structure
  • 64. ROME 27-28 march 2015 – Yan Cui @theburningmonk x.age x.name -- 42 -- β€œfoo”
  • 65. ROME 27-28 march 2015 – Yan Cui @theburningmonk x.age x.name -- 42 -- β€œfoo” .age x .name x -- 42 -- β€œfoo”
  • 66. ROME 27-28 march 2015 – Yan Cui @theburningmonk -- clone and update y = { x | name <- "bar" }
  • 67. ROME 27-28 march 2015 – Yan Cui @theburningmonk type alias Character = { age : Int, name : String }
  • 68. ROME 27-28 march 2015 – Yan Cui @theburningmonk type alias Named a = { a | name : String } type alias Aged a = { a | age : Int }
  • 69. ROME 27-28 march 2015 – Yan Cui @theburningmonk lady : Named ( Aged { } ) lady = { name=β€œfoo”, age=42 }
  • 70. ROME 27-28 march 2015 – Yan Cui @theburningmonk getName : Named x -> String getName { name } = name
  • 71. ROME 27-28 march 2015 – Yan Cui @theburningmonk getName : Named x -> String getName { name } = name ! getName lady -- β€œfoo”
  • 72. ROME 27-28 march 2015 – Yan Cui @theburningmonk type Status = Flying Pos Speed | Exploding Radius | Exploded
  • 73. ROME 27-28 march 2015 – Yan Cui @theburningmonk aka. β€œsums-and-products” data structures
  • 74. ROME 27-28 march 2015 – Yan Cui @theburningmonk type Status = Flying Pos Speed | Exploding Radius | Exploded sums : choice between variants of a type
  • 75. ROME 27-28 march 2015 – Yan Cui @theburningmonk products : tuple of types type Status = Flying Pos Speed | Exploding Radius | Exploded
  • 76. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y radius = circle radius |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)
  • 77. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y radius = circle radius |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y) filled : Color -> Shape -> Form
  • 78. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y radius = circle radius |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)
  • 79. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y radius = circle radius |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y)
  • 80. ROME 27-28 march 2015 – Yan Cui @theburningmonk β€œβ€¦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)
  • 81. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 82. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y radius = radius |> circle |> filled (rgb 150 170 150) |> alpha 0.5 |> move (x, y) 2.top-to-bottom 1. left-to-right
  • 83. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle : Int -> Int -> Float -> Form
  • 84. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = circle >> filled (rgb 150 170 150) >> alpha 0.5 >> move (x, y)
  • 85. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = circle >> filled (rgb 150 170 150) >> alpha 0.5 >> move (x, y) circle : Float -> Shape
  • 86. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> filled (rgb 150 170 150) >> alpha 0.5 >> move (x, y)
  • 87. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> filled (rgb 150 170 150) >> alpha 0.5 >> move (x, y) filled : Color -> Shape -> Form
  • 88. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> filled (rgb 150 170 150) >> alpha 0.5 >> move (x, y) Curried! filled : Color -> Shape -> Form
  • 89. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> filled (rgb 150 170 150) >> alpha 0.5 >> move (x, y) Shape -> Form
  • 90. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> (Shape -> Form) >> alpha 0.5 >> move (x, y)
  • 91. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> (Shape -> Form) >> alpha 0.5 >> move (x, y)
  • 92. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> (Shape -> Form) >> alpha 0.5 >> move (x, y)
  • 93. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Shape) >> (Shape -> Form) >> alpha 0.5 >> move (x, y)
  • 94. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Form) >> alpha 0.5 >> move (x, y)
  • 95. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Form) >> (Form -> Form) >> move (x, y)
  • 96. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Form) >> (Form -> Form) >> move (x, y)
  • 97. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Form) >> move (x, y)
  • 98. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Form) >> (Form -> Form)
  • 99. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Form) >> (Form -> Form)
  • 100. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle x y = (Float -> Form)
  • 101. ROME 27-28 march 2015 – Yan Cui @theburningmonk drawCircle : Int -> Int -> (Float -> Form)
  • 102. ROME 27-28 march 2015 – Yan Cui @theburningmonk greet name = case name of "Yan" -> β€œhi, theburningmonk" _ -> β€œhi,β€œ ++ name
  • 103. ROME 27-28 march 2015 – Yan Cui @theburningmonk greet name = case name of "Yan" -> β€œhi, theburningmonk" _ -> β€œhi,β€œ ++ name
  • 104. ROME 27-28 march 2015 – Yan Cui @theburningmonk fizzbuzz n = if | n % 15 == 0 -> "fizz buzz" | n % 3 == 0 -> "fizz" | n % 5 == 0 -> "buzz" | otherwise -> show n
  • 105. ROME 27-28 march 2015 – Yan Cui @theburningmonk Mouse.position Mouse.clicks Mouse.isDown …
  • 106. ROME 27-28 march 2015 – Yan Cui @theburningmonk Window.dimension Window.width Window.height
  • 107. ROME 27-28 march 2015 – Yan Cui @theburningmonk Time.every Time.fps Time.timestamp Time.delay …
  • 108. ROME 27-28 march 2015 – Yan Cui @theburningmonk Mouse.position : Signal (Int, Int)
  • 109. ROME 27-28 march 2015 – Yan Cui @theburningmonk Mouse.position : Signal (Int, Int)
  • 110. ROME 27-28 march 2015 – Yan Cui @theburningmonk Mouse.position : Signal (Int, Int) (10, 23) (3, 16) (8, 10) (12, 5) (18, 3)
  • 111. ROME 27-28 march 2015 – Yan Cui @theburningmonk Keyboard.lastPressed : Signal Int
  • 112. ROME 27-28 march 2015 – Yan Cui @theburningmonk Keyboard.lastPressed : Signal Int H E L L O space
  • 113. ROME 27-28 march 2015 – Yan Cui @theburningmonk Keyboard.lastPressed : Signal Int H E L L O space 72 69 76 76 79 32
  • 114. ROME 27-28 march 2015 – Yan Cui @theburningmonk map : (a -> b) -> Signal a -> Signal b
  • 115. ROME 27-28 march 2015 – Yan Cui @theburningmonk <~
  • 116. ROME 27-28 march 2015 – Yan Cui @theburningmonk Signal of num of pixels in window
  • 117. ROME 27-28 march 2015 – Yan Cui @theburningmonk ((w, h) -> w*h) <~ Window.dimensions
  • 118. ROME 27-28 march 2015 – Yan Cui @theburningmonk ((w, h) -> w*h) <~ Window.dimensions Signal (Int, Int)(Int, Int) -> Int
  • 119. ROME 27-28 march 2015 – Yan Cui @theburningmonk ((w, h) -> w*h) <~ Window.dimensions Signal (Int, Int)(Int, Int) -> Int Signal Int
  • 120. ROME 27-28 march 2015 – Yan Cui @theburningmonk (10, 10) (15, 10) (18, 12) 100 150 216 ((w, h) -> w*h) <~ Window.dimensions
  • 121. ROME 27-28 march 2015 – Yan Cui @theburningmonk map2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
  • 122. ROME 27-28 march 2015 – Yan Cui @theburningmonk ~
  • 123. ROME 27-28 march 2015 – Yan Cui @theburningmonk (,) <~ Window.width ~ Window.height Signal Int a -> b -> (a, b) Signal Int
  • 124. ROME 27-28 march 2015 – Yan Cui @theburningmonk (,) <~ Window.width ~ Window.height Signal Int Int -> Int -> (Int, Int) Signal Int
  • 125. ROME 27-28 march 2015 – Yan Cui @theburningmonk map3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
  • 126. ROME 27-28 march 2015 – Yan Cui @theburningmonk (,,) <~ signalA ~ signalB ~ signalC
  • 127. ROME 27-28 march 2015 – Yan Cui @theburningmonk map4 : … map5 : … map6 : … map7 : … map8 : …
  • 128. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp : (a -> b -> b) -> b -> Signal a -> Signal b
  • 129. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp : (a -> b -> b) -> b -> Signal a -> Signal b
  • 130. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp : (a -> b -> b) -> b -> Signal a -> Signal b
  • 131. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp : (a -> b -> b) -> b -> Signal a -> Signal b
  • 132. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp : (a -> b -> b) -> b -> Signal a -> Signal b
  • 133. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp : (a -> b -> b) -> b -> Signal a -> Signal b
  • 134. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp (_ n -> n + 1) 0 Mouse.clicks
  • 135. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp (_ n -> n + 1) 0 Mouse.clicks
  • 136. ROME 27-28 march 2015 – Yan Cui @theburningmonk foldp (_ n -> n + 1) 0 Mouse.clicks
  • 137. ROME 27-28 march 2015 – Yan Cui @theburningmonk 1 3 42 5 foldp (_ n -> n + 1) 0 Mouse.clicks
  • 138. ROME 27-28 march 2015 – Yan Cui @theburningmonk UP { x=0, y=1 } DOWN { x=0, y=-1 } LEFT { x=-1, y=0 } RIGHT { x=1, y=0 }
  • 139. ROME 27-28 march 2015 – Yan Cui @theburningmonk merge : Signal a -> Signal a -> Signal a mergeMany : List (Signal a) -> Signal a …
  • 140. ROME 27-28 march 2015 – Yan Cui @theburningmonk Js Interop, WebGL HTML layout, dependency management, etc.
  • 141. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 142. ROME 27-28 march 2015 – Yan Cui @theburningmonk 8 segments
  • 143. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction
  • 144. ROME 27-28 march 2015 – Yan Cui @theburningmonk change change no changenot allowed direction
  • 145. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction
  • 146. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction
  • 147. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction
  • 148. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction
  • 149. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction cherry
  • 150. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction YUMYUMYUM!
  • 151. ROME 27-28 march 2015 – Yan Cui @theburningmonk direction +1 segment
  • 152. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 153. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 154. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 155. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 156. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 157. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 158. ROME 27-28 march 2015 – Yan Cui @theburningmonk Demo
  • 159. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 160. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 161. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 162. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 163. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 164. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 165. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 166. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 167. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 168. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 169. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 170. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 171. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 172. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 173. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 174. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 175. ROME 27-28 march 2015 – Yan Cui @theburningmonk github.com/theburningmonk/elm-snake github.com/theburningmonk/elm-missile- command Missile Command Snake
  • 176. ROME 27-28 march 2015 – Yan Cui @theburningmonk elm-lang.org/try debug.elm-lang.org/try
  • 177. ROME 27-28 march 2015 – Yan Cui @theburningmonk the
  • 179. Β so
  • 182. ROME 27-28 march 2015 – Yan Cui @theburningmonk Type error between lines 63 and 85: case gameState of NotStarted - if | userInput == Space - Started (defaultSnake,Nothing) | True - gameState Started ({segments,direction},cherry) - let arrow = case userInput of Arrow arrow - arrow _ - {x = 0, y = 0} newDirection = getNewDirection arrow direction newHead = getNewSegment (List.head segments) newDirection newTail = List.take ((List.length segments) - 1) segments (w,h) = windowDims isGameOver = (List.any (t - t == newHead) newTail) || (((fst newHead) ((toFloat w) / 2)) || (((snd newHead) ((toFloat h) / 2)) || (((fst newHead) ((toFloat (-w)) / 2)) || ((snd newHead) ((toFloat (-h)) / 2))))) in if | isGameOver - NotStarted | True - Started ({segments = newHead :: newTail, direction = newDirection}, cherry) ! Expected Type: {} Actual Type: Snake.Input cryptic error messages
  • 183. ROME 27-28 march 2015 – Yan Cui @theburningmonk breaking changes
  • 184. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 185. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 186. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 187. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 188. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 189. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 190. ROME 27-28 march 2015 – Yan Cui @theburningmonk
  • 191. ROME 27-28 march 2015 – Yan Cui @theburningmonk @theburningmonk github.com/theburningmonk theburningmonk.com
  • 192.
  • 194. ROME 27-28 march 2015 – Yan Cui @theburningmonk Leave your feedback on Joind.in! https://joind.in/14145 ! !