Skip to content

Instantly share code, notes, and snippets.

@deflexor
Last active October 14, 2015 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deflexor/91764a87ce1b1fdbaa2c to your computer and use it in GitHub Desktop.
Save deflexor/91764a87ce1b1fdbaa2c to your computer and use it in GitHub Desktop.
Elm-lang app that needs speed boost
import Html exposing (..)
import Debug exposing (..)
import Array exposing (Array, repeat, set, get, toList, initialize)
import Html.Attributes exposing (..)
import Html.Events exposing (on, onClick, targetChecked)
import Signal exposing (Address)
import StartApp.Simple as StartApp
main =
StartApp.start { model = initialModel, view = view, update = update }
-- MODEL
type alias Model = Array Bool
w = 400
h = 400
initialModel = repeat (w * h) False
-- UPDATE
type Action
= Hi Int
update action model =
case action of
Hi i ->
let newval = if (get i model) == Just True then False else True
in
set i newval model
-- VIEW
view address model =
table [ style [("border-collapse", "collapse")] ] (toList (initialize h (\row ->
tr [] (toList (initialize w (\col ->
let i = w*row+col
bg = if (get i model)== Just True then "blue" else "white"
in
td [ onClick address (Hi i), style [("background", bg)] ] [ text "*" ]
)))
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment