elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.55k stars 662 forks source link

- and + behave inconsistently #2329

Open Golden-Phy opened 5 months ago

Golden-Phy commented 5 months ago

Quick Summary: Miss-formatting of an infix subtraction can lead to an interesting phenomena, where the first operand is interpreted as a function and the second as an argument, leading to the compiler saying that a number doesn't take that many arguments. Doing the same with + works fine though. My assumption is that - is treated as unary operator, something that the + operator apparently doesn't support.

SSCCE

module Main exposing (..)

import Browser
import Html exposing (Html, div, text)

-- MAIN
main =
  Browser.sandbox { init = init, update = update, view = view }

-- UPDATE
update : () -> Model -> Model
update _ model =
  model

-- MODEL
type alias Model = ()

init : Model
init = ()

-- VIEW
view : Model -> Html ()
view model =
    div [] [text (String.fromInt(1 -1))]
--    div [] [text (String.fromInt(1 - 1))]
--    div [] [text (String.fromInt(1 +1))]
-- Example illustrating the interpretation of the compiler (at least for me)
--    div [] [text (String.fromInt(1 -1 * 2))]

Additional Details

Compiler output:

TOO MANY ARGS
Jump to problem
This value is not a function, but it was given 1 argument.

24|     div [] [text (String.fromInt(1 -1))]

                                     ^
Are there any missing commas? Or missing parentheses?
github-actions[bot] commented 5 months ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

nopria commented 5 months ago

I was thinking about adopting ELM for a project but the fact that basic issues like this one are not likely to be solved any time soon leads me to look for an alternative.