Yes, it is. So if you add module Main exposing (..) (two dots not three) to the top line, it will compile. I haven’t used Ellie myself, so don’t know its history - this error may be a throwback from when Ellie didn’t require it - Maybe. Just a thought.
Yes, if you want to extend the example to add more conversions, then you will need to change the model accordingly. Rather than just calling the input box input, you could name them all to be something more specific.
What exactly don’t you understand? It takes data from either of the Maybe branches and displays it in the Dom. If you could be more specific it would be helpful.
You won’t be able to use viewConverter the same way as in the original example. The parameters passed in are being used for both inputs etc, so changing the value in one, will also change the value in the other. I guess you have already seen this happening.
If you break this down into two separate functions, it should start to become easier to solve.
celsiusViewConverter : String -> String -> String -> Html Msg
celsiusViewConverter userInput color equivalentTemp =
span []
[ input [ value userInput, onInput ChangeCelsius, style "width" "40px" ] []
, text "°C = "
, span [ style "color" color ] [ text equivalentTemp ]
, text "°F"
]
farenheitViewConverter : String -> String -> String -> Html Msg
farenheitViewConverter userInput color equivalentTemp =
span []
[input [ value userInput, onInput ChangeFahrenheit, style "width" "40px" ] []
, text "°F = "
, span [ style "color" color ] [ text equivalentTemp ]
, text "°C"
]
Then you can use those functions in your view:
view : Model -> Html Msg
view model =
let
celsiusView =
case String.toFloat model.inputCelsius of
Just celsius ->
celsiusViewConverter model.inputCelsius "blue" (String.fromFloat (celsius * 1.8 + 32))
Nothing ->
celsiusViewConverter model.inputCelsius "red" "???"
farenheitView =
case String.toFloat model.inputFarenheit of
Just farenheit ->
farenheitViewConverter model.inputFarenheit "blue" (String.fromFloat (fahrenheit/2))
Nothing ->
farenheitViewConverter model.inputFarenheit "red" "???"
in
span []
[ celsiusView, farenheitView ]
There’s more than one way to skin a cat, but hopefully, this shows you the simplest approach.