@JoGrenat #elmlang
@JoGrenat
null > 0 // false
null == 0 // false
null >= 0 // ... true
JS syntax size
Time
ES6
By Chris Williams
17K+ LoC
200K+ LoC
Functional programming is a way of writing programs by using pure functions and avoiding mutable data and side-effects
BLABLABLA
function sendEmail(user) {
}
No unwanted side-effect
function sendEmail(user) {
if (user.email === null) {
throw new Error('No email provided for the user');
}
}
function sendEmail(user) {
if (user.email === null) {
throw new Error('No email provided for the user');
}
launchNuclearMissile();
}
Side-effect = command, explicitely declared
"Elm has a very strong emphasis on simplicity, ease-of-use, and quality tooling."
1.2.3
Nothing changed for the outside
Something was added
Something has changed
See also Building Trust: What Has Worked by Richard Feldman
and What is success? by Evan Czaplicki
I call it my billion-dollar mistake. It was the invention of the null reference in 1965. [...] This has led to innumerable errors, vulnerabilities, and system crashes [...]
– Tony Hoare –
let
in
twentyFour + sixteen
3 * 8 + 4 * 4
let
twentyFour =
3 * 8
sixteen =
4 * 4
in
twentyFour + sixteen
case myNumber of
0 ->
"Zero"
1 ->
"One"
anythingElse ->
"Nor 0 nor 1"
case myNumber of
0 ->
"Zero"
1 ->
"One"
_ ->
"Nor 0 nor 1"
case myStringMaybe of
Just myString ->
"myStringMaybe contains: " ++ myString
Nothing ->
"myStringMaybe contains nothing"
myStringMaybe = Just "Hello"
"Hello"
Cmd Msg
?
Runtime
Cmd Msg
Generator CoinState
main : Program Never Model Msg
main =
element { view = view, init = init, update = update, subscriptions = subscriptions }
-- ...
subscriptions : Model -> Sub Msg
subscriptions model =
usernameFromLS ReceivedUsernameFromLS
port registerUsernameToLS : String -> Cmd msg
port usernameFromLS : (String -> msg) -> Sub msg
const app = Elm.Main.init({node: root});
app.ports.registerUsernameToLS.subscribe(username => {
window.localStorage.setItem('username', username)
});
if (window.localStorage.getItem('username') !== null) {
const username = window.localStorage.getItem('username');
app.ports.usernameFromLS.send(username);
}
module Tests exposing (..)
import Test exposing (..)
import Expect
import App exposing (update, Msg(CoinFlipped), CoinState(Heads))
all : Test
all =
describe "A CoinFlipped should start a new game"
[ test <|
\() ->
Expect.equal (update (CoinFlipped Heads) NoGame) (Game Heads)
]