evincarofautumn / kitten

A statically typed concatenative systems programming language.
http://kittenlang.org/
Other
1.1k stars 42 forks source link

No multiline generic lambdas in REPL #198

Open Camto opened 6 years ago

Camto commented 6 years ago

I have a program Say lambda.ktn which contains:

6
-> x {x say}
call
"Lambda!"
-> x {x say}
call

It prints

6
Lambda!

And when I type in the console 6 -> x {x say} call it prints 6, so far so good. But when I type 6, -> x {x say}, and call in separate lines (like in the file), it says I can't find an instantiation of '_::show': _::show<T>, which it should not. It should print 6. It says the same error for "Lambda!".

evincarofautumn commented 6 years ago

Thanks for bringing this to my attention. I was aware of this bug, but unfortunately I haven’t found a great way to solve it yet.

Essentially, each entry in the console is added to the interpreter state as a separate definition, partly so that they can be referenced later as interactive::entryN. When one of these definitions is generic, like -> x { x say } by itself†, the compiler fails to generate an instantiation of that definition for a particular concrete type, so instead of looking up show<Int32> or show<List<Char>>, it tries to look up the generic show<T>, which fails because that’s not a real instance definition.

For now you can work around this by avoiding generic entries in interactive mode, or using a source file, but I’ll bump this up on my to-do list and figure out how to fix it properly.

†NB: This is unrelated to your question, but the type of -> x { x say } is currently slightly wrong as well: it’s inferred as <T> (-> (T -> +IO)), but it should eventually include a trait constraint, something like <T> (-> (T -> +IO)) where (show<T>). This should help the compiler produce a better error message in similar situations.

Camto commented 6 years ago

Thanks for the response. I hope you can find an answer!