effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
319 stars 23 forks source link

REPL throws an error when attempting to show a term on LLVM #474

Open jiribenes opened 4 months ago

jiribenes commented 4 months ago

Problem

When I put an expression into the REPL, the REPL tries to call println($EXPR) which fails for all non-trivial types since #449:

> type TrafficLight { Red(); Yellow(); Green() }
> Red()
[error] Cannot typecheck call.
There are multiple overloads, which all fail to check:
[...]
Full error ``` Possible overload: option::println of type Option[Double] => Unit Argument count does not match TrafficLight2360 vs. Option593 Expected type Option[Double] but got type TrafficLight Possible overload: effekt::println of type String => Unit Expected String but got TrafficLight. Possible overload: effekt::println of type Int => Unit Expected Int but got TrafficLight. Possible overload: array::println of type Array[String] => Unit Argument count does not match TrafficLight2360 vs. Array1667 Expected type Array[String] but got type TrafficLight Possible overload: option::println of type Option[Bool] => Unit Argument count does not match TrafficLight2360 vs. Option593 Expected Option[Bool] but got TrafficLight. Possible overload: list::println of type List[Int] => Unit Argument count does not match TrafficLight2360 vs. List767 Expected List[Int] but got TrafficLight. Possible overload: option::println of type Option[Int] => Unit Argument count does not match TrafficLight2360 vs. Option593 Expected Option[Int] but got TrafficLight. Possible overload: list::println of type List[Double] => Unit Argument count does not match TrafficLight2360 vs. List767 Expected List[Double] but got TrafficLight. Possible overload: effekt::println of type Unit => Unit Expected Unit but got TrafficLight. Possible overload: list::println of type List[String] => Unit Argument count does not match TrafficLight2360 vs. List767 Expected List[String] but got TrafficLight. Possible overload: array::println of type Array[Bool] => Unit Argument count does not match TrafficLight2360 vs. Array1667 Expected Array[Bool] but got TrafficLight. Possible overload: effekt::println of type Double => Unit Expected Double but got TrafficLight. Possible overload: array::println of type Array[Double] => Unit Argument count does not match TrafficLight2360 vs. Array1667 Expected type Array[Double] but got type TrafficLight Possible overload: list::println of type List[Bool] => Unit Argument count does not match TrafficLight2360 vs. List767 Expected List[Bool] but got TrafficLight. Possible overload: effekt::println of type Ordering => Unit Expected Ordering but got TrafficLight. Possible overload: effekt::println of type Bool => Unit Expected Bool but got TrafficLight. Possible overload: array::println of type Array[Int] => Unit Argument count does not match TrafficLight2360 vs. Array1667 Expected Array[Int] but got TrafficLight. ```

Source

Here's the code in question which just calls println on terms: https://github.com/effekt-lang/effekt/blob/aa897e4f70407d5086d0da093ce04824bf43acee/effekt/jvm/src/main/scala/effekt/Repl.scala#L318-L319

Potential solution

If we don't want to wait for typeclasses #66, we could instead use inspect introduced in #449 because the REPL always runs with the JavaScript backend: EDIT: Not true, the REPL runs with the backend of user's choice, see below. The workaround would only work for the JS and Chez backends https://github.com/effekt-lang/effekt/blob/aa897e4f70407d5086d0da093ce04824bf43acee/libraries/common/effekt.effekt#L102-L104

marvinborner commented 4 months ago

the REPL always runs with the JavaScript backend:

For debugging I often use different backends in the REPL, e.g. via effekt.sh --backend llvm Am I misunderstanding this?

jiribenes commented 4 months ago

Thanks, I took a closer look and invalidated my assumption. The REPL runs for any backend... I'll fix it in the original issue description.