Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Created November 14, 2014 11:29
Show Gist options
  • Save doloopwhile/584d1a36f93940bc1823 to your computer and use it in GitHub Desktop.
Save doloopwhile/584d1a36f93940bc1823 to your computer and use it in GitHub Desktop.
elm add
import String
import Graphics.Input (Input, input)
import Graphics.Input.Field as Field
lhd : Input Field.Content
lhd = input Field.noContent
rhd : Input Field.Content
rhd = input Field.noContent
main : Signal Element
main = lift2 scene lhd.signal rhd.signal
scene : Field.Content -> Field.Content -> Element
scene lContent rContent =
flow right
(map (\x -> (container 50 50 middle (width 50 x)))
[
Field.field Field.defaultStyle lhd.handle identity "" lContent
, plainText ("+")
, Field.field Field.defaultStyle rhd.handle identity "" rContent
, plainText ("=")
, plainText (add (String.toInt lContent.string) (String.toInt rContent.string))
])
add : Maybe Int-> Maybe Int -> String
add xstr ystr =
case xstr of
Nothing -> "err"
Just x ->
case ystr of
Nothing -> "err"
Just y -> String.show (x + y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment