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
type Msg | |
= Add | |
| Sub | |
| Mult | |
| Div | |
| Operator1Changed String | |
| Operator2Changed String |
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
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
Add -> | |
let | |
res = | |
model.op1 + model.op2 | |
in | |
( { model | result = res }, Cmd.none ) |
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
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div | |
[] | |
[ div | |
[] | |
[ input [ id "operator1", onInput Operator1Changed ] [ text (toString model.op1) ] |
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
-- MODEL | |
type alias Model = | |
{ -- We are forced to use float to avoid runtime exceptions in DIV operation | |
op1 : Float | |
, op2 : Float | |
, result : Float | |
} |