Created
November 14, 2014 11:29
-
-
Save doloopwhile/584d1a36f93940bc1823 to your computer and use it in GitHub Desktop.
elm add
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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