I hereby claim:
- I am mindbat on github.
- I am mindbat (https://keybase.io/mindbat) on keybase.
- I have a public key ASBaRUcaZn3Q4UeRJEmEJywORliem0tq5njUwVDmu3QThAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
import Color exposing (..) | |
import Collage exposing (..) | |
import Element exposing (Element, image, leftAligned, toHtml) | |
import Html exposing (Html) | |
import Keyboard exposing (..) | |
import Key exposing (..) | |
import List exposing ((::), all, filter, length) | |
import Mouse exposing (..) | |
import Random exposing (Seed, step, initialSeed, int) | |
import Text exposing (color, fromString, height, monospace) |
The Elm examples given in the book (especially from Day Two, forward) are for an older version of Elm. Elm 0.17 changed a lot of things in the language, including eliminating signals and moving a lot of the libraries around.
I’ve translated the Day Two examples from the book to run on Elm 0.18
Elm 0.17+ avoids callbacks using Subscriptions, not Signals: https://gist.github.com/mindbat/7afc23cad8da000e4b26de55986d4eaf
For all three of these examples, we need to swap signals for subscriptions:
import Color exposing (..) | |
import Collage exposing (..) | |
import Element exposing (..) | |
carBottom = filled black (rect 160 50) | |
carTop = filled black (rect 100 60) | |
tire = filled red (circle 24) | |
car = collage 300 300 | |
import Html exposing (Html, text, input, div) | |
import Html.App as App | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (onInput) | |
import String | |
main = App.program { init = init, | |
view = view, update = update, subscriptions = \_ -> Sub.none } | |
-- Model |
import Html exposing (Html, text, div) | |
import Html.App as App | |
import Mouse exposing (..) | |
main = App.program { init = init, | |
view = view, update = update, subscriptions = subscriptions } | |
-- Model | |
type alias Model = { x: Int, y : Int } |
import Html exposing (Html, text, div) | |
import Html.App as App | |
import Mouse exposing (..) | |
main = App.program { init = init, | |
view = view, update = update, subscriptions = subscriptions } | |
-- Model | |
type alias Model = { count: Int } |
import Html exposing (Html, text, div) | |
import Html.App as App | |
import Mouse exposing (..) | |
main = App.program { init = init, | |
view = view, update = update, subscriptions = subscriptions } | |
-- Model | |
type alias Model = { count: Int } |
import Html exposing (Html, text, div) | |
import Html.App as App | |
import Mouse exposing (..) | |
main = App.program { init = init, | |
view = view, update = update, subscriptions = subscriptions } | |
-- Model | |
type alias Model = { x: Int, y: Int } |
safeHead :: [a] -> [a] | |
safeHead x = take 1 x | |
safeTail :: [a] -> [a] | |
safeTail x = drop 1 x | |
safeInit :: [a] -> [a] | |
safeInit x = take ((length x) - 1) x | |
safeLast :: [a] -> [a] |