10/02/2016 - Elm London Meetup
Why use statically typed pure Functional languages?
Elm is a Functional Reactive Language for interactive applications.
As seen on LambdaCat:
foldp : (a -> state -> state) -> state -> Signal a ->
Signal state
merge : Signal a ->
type Tile
= Door Size
| Column
| BackGround BackGroundTile
| Shadow ShadowTile
type Maybe a
= Just a
| Nothing
String.toInt : String -> Maybe Int
toMonth : String -> Maybe Int toMonth rawString =
case String.toInt rawString of
Nothing ->
Nothing
Just n ->
if n > 0 && n <= 12 then Just n else Nothing
type alias UserInput = {}
userInput : Signal UserInput
userInput = Signal.constant {}
type alias Input =
{ timeDelta : Float
, userInput : UserInput
}
type alias UserInput = {}
userInput : Signal UserInput
userInput = Signal.constant {}
type alias Input =
{ timeDelta : Float
, userInput : UserInput
}
type alias UserInput = {}
userInput : Signal UserInput
userInput = Signal.constant {}
type alias Input =
{ timeDelta : Float
, userInput : UserInput
}
type alias GameState = {}
defaultGame : GameState
defaultGame = {}
display : (Int,Int) -> GameState -> Element
display (w,h) gameState = show gameState
display : (Int,Int) -> GameState -> Element
display (w,h) gameState = show gameState
stepGame : Input -> GameState -> GameState
stepGame {timeDelta,userInput} gameState =
gameState
delta : Signal Float
delta = Time.fps 30
input : Signal Input
input = Signal.sampleOn delta
(Signal.map2 Input delta userInput)
delta : Signal Float
delta = Time.fps 30
input : Signal Input
input = Signal.sampleOn delta
(Signal.map2 Input delta userInput)
gameState : Signal GameState
gameState = Signal.foldp stepGame
defaultGame input
gameState : Signal GameState
gameState = Signal.foldp stepGame
defaultGame input
main : Signal Element
main = Signal.map2 display
Window.dimensions gameState
main : Signal Element
main = Signal.map2 display
Window.dimensions gameState
foldp takes (a -> state -> state)
a function
... -> state -> ...
a default state
... -> Signal a -> ...
an input signal
... -> Signal state
returns a signal
(= next state of the program, after applying update)