koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

Index name issue #436

Closed TimWhiting closed 5 months ago

TimWhiting commented 5 months ago

Discussed in https://github.com/koka-lang/koka/discussions/434

Originally posted by **chtenb** January 16, 2024 Example code that demonstrates this error: ```koka fun copy-and-replace-at(v : vector, index : int, new : a) : exn vector var result := v result[index] := new result ``` Full error: ``` repro.kk(3, 9): error: only functions or types with a copy constructor can be applied context : [index] := new term : [index] inferred type: int ``` What does this error mean exactly, and how would I write code like this without triggering this error?
daanx commented 5 months ago

ha ha, that is a funny bug... if you rename index to say ndex it works :-) I think I introduced this bug when streamlining identifiers recently and using the name index for the previous [_] method. I'll fix this asap.

edit: I see what happens, the expression result[index] is translated into index(result,index) ..

daanx commented 5 months ago

Fixed now in dev. I may redesign this a bit more but perhaps first I'll update the spec with the new grammar changes to identifiers. Thanks again!