Problem
I made my first small mistake and Morel responded with three screens of text. I want a quick translation guide so I can fix it and move on.
Example
Add a string to a number and see what Morel says:
val x = 1 + "two";
stdIn:1.1-1.18 Error: Cannot deduce type: conflict: int vs string
raised at: stdIn:1.1-1.18
What's happening
Morel's type errors read like a telegram, but there's always a verb
and a subject. "Cannot deduce type" is the verb — inference didn't
converge. "Conflict: int vs string" is the subject — two expressions
were unified and one wants an int, the other a string. Here +
is polymorphic over numeric types, gets pinned to int by the
literal 1, and then "two" is asked to be an int and refuses.
The fix is always the same: find which expression drove the first constraint and which one disagreed. Change either side to match and it compiles.
Two other errors you'll hit in the first hour:
val row = { id = 1, product = "Earl Grey", quantity = 12 };
row.prodcut;
stdIn:1.5-1.12 Error: no field 'prodcut' in type '{id:int, product:string, quantity:int}'
raised at: stdIn:1.5-1.12
This one is a gift. Morel prints the whole record type so you can see the fields it does know about, misspelled or otherwise. Copy the name from the error message rather than retyping it.
ordders;
stdIn:1.1-1.8 Error: unbound variable or constructor: ordders
raised at: stdIn:1.1-1.8
A plain unbound is almost always a typo or an out-of-order binding.
Morel evaluates top to bottom, so if val orders = … comes after the
ordders reference, fix the order.
One thing Morel will not help with yet: when you forget a trailing
; on a val, the REPL keeps reading the next line as if it were
part of the previous expression. The prompt changes from - to =.
That's your hint — type ; and hit enter to eject.
Variations
Read the span before the message. stdIn:1.5-1.12 is
line.column-line.column counted from the start of the statement you
just entered, pointing at exactly the .prodcut that went wrong.
raised at: marks the expression that actually failed — for a runtime
error, inside the function that blew up, not the call you typed.
Morel 0.8 printed 0.0-0.0 for everything. 0.9 populates most spans
but not all — a duplicate record field still reports zeroes. When it
does, ignore the number and read the message.
See also
- Recipe 01 — First query — has the kind of snippet that will generate these errors if you fumble it.
- Recipe 02 — Values, records, and lists — what the
{id:int, ...}shape in the error actually means.