Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suboptimal error for mising function arguments #2326

Open
Golden-Phy opened this issue May 25, 2024 · 1 comment
Open

Suboptimal error for mising function arguments #2326

Golden-Phy opened this issue May 25, 2024 · 1 comment

Comments

@Golden-Phy
Copy link

Quick Summary: The compiler brings up a type mismatch between function x -> type and type when trying to use the result of a partial function call. It does not give a hint that the user might want to apply the function to x by giving it as a parameter.

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 = Chain

type Chain 
  = Empty
  | Node Chain
init : Model
init = Node (Node Empty)

-- VIEW
view : Model -> Html ()
view model =
    div [] (render 
      model 
-- 2.      1
    )
    
    
render : Chain -> Int -> List (Html ())
render chain depth =
  case chain of
    Empty -> []
    Node subChain -> 
      (render 
        subChain 
-- 1.        (depth + 1)
      )
      ++ [div [] [text (String.fromInt depth)]]
  • Elm: Playground on https://elm-lang.org/try as of 5/25/2024
  • Browser: Mozilla Firefox for Fedora 123.0 (64)
  • Operating System: Fedora Linux 39

Additional Details

Compiler output:

TYPE MISMATCH
Jump to problem
The (++) operator cannot append this type of value:

38|>      (render 

39|>        subChain 

40| -- 1.        (depth + 1)

41|       )

42|       ++ [div [] [text (String.fromInt depth)]]

This `render` call produces:

    Int -> List (Html ())

But the (++) operator is only for appending List and String values. Maybe put
this value in [] to make it a list?

Hint: I only know how to append strings and lists.
Copy link

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant