Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upDict.insert returns misleading error when 2 arguments instead of 3 are passed #733
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
It's fine to pass two arguments to
This produces (0.17, 0.18)
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 The best place for this is likely the error message catalog. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Yes, this belongs on the error message catalog, not here. |
kkruups commentedOct 16, 2016
•
edited
Edited 1 time
-
kkruups
edited Oct 17, 2016 (most recent)
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) vnfDictSTARTOF ERR MSG --------------------------
-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm
The 1st argument to function
insertis causing a mismatch.6| Dict.insert ("C", vnfC) vnfDict
^^^^^^^^^^^
Function
insertis 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 vnfDictResult:
Dict.fromList [("A",{ veg = "Artichoke", fruit = "Apple" }),("B",{ veg = "Artichoke", fruit = "Apple" }),("C",{ veg = "Calaloo", fruit = "Cranberry" })]
: Dict.Dict String Repl.VegnFruit