From ee4c3bc9b6a647c13af4c28ccd45a6adc0e5d5c3 Mon Sep 17 00:00:00 2001 From: sforman Date: Wed, 2 Aug 2023 21:19:43 -0700 Subject: [PATCH] Thread the dict through the interaction loop. Like a total newbie I put the call to the interpreter in the view function instead of the update function! I thought it was weird having to specify the HTML twice, but I figured I was just doing it wrong. I was, but not in the way I suspected. In any event, I like how this make it clear that errors can't affect the dictionary. --- implementations/Elm/src/Main.elm | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/implementations/Elm/src/Main.elm b/implementations/Elm/src/Main.elm index 2fda55e..83100ad 100644 --- a/implementations/Elm/src/Main.elm +++ b/implementations/Elm/src/Main.elm @@ -22,13 +22,14 @@ main = type alias Model = { content : String + , evaluated : String , dictionary : JoyDict } init : Model init = - { content = "", dictionary = initialize Dict.empty } + { content = "", evaluated = "", dictionary = initialize Dict.empty } @@ -43,7 +44,11 @@ update : Msg -> Model -> Model update msg model = case msg of Change newContent -> - { model | content = newContent } + case doit newContent model.dictionary of + Err err -> + { model | content = newContent, evaluated = err} + Ok (output, dict) -> + { content = newContent, evaluated = output, dictionary = dict } @@ -52,15 +57,8 @@ update msg model = view : Model -> Html Msg view model = - case doit model.content model.dictionary of - Err msg -> div [] [ input [ placeholder "Text to reverse", value model.content, onInput Change ] [] - , div [] [ text msg ] - ] - Ok (message, dict0) -> - div [] - [ input [ placeholder "Text to reverse", value model.content, onInput Change ] [] - , div [] [ text message ] + , div [] [ text model.evaluated ] ]