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

Dict.insert returns misleading error when 2 arguments instead of 3 are passed #733

Closed
kkruups opened this Issue Oct 16, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@kkruups

kkruups commented Oct 16, 2016


Issue

Dict.insert: comparable -> a -> Dict comparable a -> Dict comparable a

When sending Dict.insert two arguments, a tuple and Dict, instead of three, the error message is misleading. Note the tuple has the same shape as the entries in the Dict

With Dict.insert using 2 arguments

This doesn't work:

Dict.insert ("C", vnfC) vnfDict (only two args)
(where vnfC = {veg:"Calaloo", fruit:"Cranberry"}

and

vnfDict is Dict with two entries:

Dict.fromList
[("A",{ veg = "Artichoke", fruit = "Apple" }),("B",{ veg = "Artichoke", fruit = "Apple" })] : Dict.Dict String Repl.VegnFruit.)
`


Expected Behavior

One of the following

Either
1. Indicate missing argument error message

or

2.Add the entry into Dict if it has same shape as entries of Dict.


Error Message Indicated* ( when executing with Dict.insert with 2 Args):

Dict.insert ("C", vnfC) vnfDict
STARTOF ERR MSG --------------------------

-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm

The 1st argument to function insert is causing a mismatch.

6| Dict.insert ("C", vnfC) vnfDict
^^^^^^^^^^^
Function insert is expecting the 1st argument to be:

( String, VegnFruit )

But it is:

( String, VegnFruit )

Hint: Only ints, floats, chars, strings, lists, and tuples are comparable.`

END OF ERR MSG --------------------------


With Dict.insert using 3 arguments:

This works: `

Dict.insert "C" vnfC vnfDict

Result:
Dict.fromList [("A",{ veg = "Artichoke", fruit = "Apple" }),("B",{ veg = "Artichoke", fruit = "Apple" }),("C",{ veg = "Calaloo", fruit = "Cranberry" })]
: Dict.Dict String Repl.VegnFruit


@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Oct 16, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Oct 16, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@mgold

This comment has been minimized.

Show comment
Hide comment
@mgold

mgold Oct 17, 2016

Contributor

It's fine to pass two arguments to Dict.insert; you just get back a function. Here's an SSCCE of the real problem:

import Dict

Dict.insert ("C", Nothing) Dict.empty

This produces (0.17, 0.18)

-- TYPE MISMATCH ---------------------------------------------

The 1st argument to function `insert` is causing a mismatch.

4|   Dict.insert ("C", Nothing) Dict.empty
                 ^^^^^^^^^^^^^^
Function `insert` is expecting the 1st argument to be:

    ( String, Maybe a )

But it is:

    ( String, Maybe a )

Hint: Only ints, floats, chars, strings, lists, and tuples are comparable.

The "expected first argument" is shown to be the same as the "but it is", which is a pretty bad error message. The problem with this code is that Nothing is not comparable, and therefore the tuple is not an acceptable key. I'd guess the root cause has something to do with how comparable types are handled. The error is reasonable if you try Dict.insert Nothing Dict.empty.

The best place for this is likely the error message catalog.

Contributor

mgold commented Oct 17, 2016

It's fine to pass two arguments to Dict.insert; you just get back a function. Here's an SSCCE of the real problem:

import Dict

Dict.insert ("C", Nothing) Dict.empty

This produces (0.17, 0.18)

-- TYPE MISMATCH ---------------------------------------------

The 1st argument to function `insert` is causing a mismatch.

4|   Dict.insert ("C", Nothing) Dict.empty
                 ^^^^^^^^^^^^^^
Function `insert` is expecting the 1st argument to be:

    ( String, Maybe a )

But it is:

    ( String, Maybe a )

Hint: Only ints, floats, chars, strings, lists, and tuples are comparable.

The "expected first argument" is shown to be the same as the "but it is", which is a pretty bad error message. The problem with this code is that Nothing is not comparable, and therefore the tuple is not an acceptable key. I'd guess the root cause has something to do with how comparable types are handled. The error is reasonable if you try Dict.insert Nothing Dict.empty.

The best place for this is likely the error message catalog.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Oct 17, 2016

Contributor

Yes, this belongs on the error message catalog, not here.

Contributor

jvoigtlaender commented Oct 17, 2016

Yes, this belongs on the error message catalog, not here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment