brownplt / pyret-lang

The Pyret language.
Other
1.06k stars 106 forks source link

Issue with the array type #1728

Open sorawee opened 3 months ago

sorawee commented 3 months ago
import arrays as arr

fun test(xs :: Array<Number>):
  xs.get-now(1)
end

fails with

The type checker rejected your program because it found a Any but it expected a a polymorphic type

when it's run with the type checker on.

However, this program works fine.


import arrays as arr

fun test(xs :: arr.Array<Number>):
  xs.get-now(1)
end

It looks like something's gone wrong with the default namespace?

Originally reported by B Nagy András in Discord.

blerner commented 2 months ago

@jpolitz this one's weird -- I think this has to do with the fact that Array is declared as a newtype in arrays.arr, and not really as a data, and the newtype declaration doesn't have any way to indicate that it has type arguments? So I'm actually more surprised that the second example does type-check, since I see no reason from the arrays code that it should.

jpolitz commented 2 months ago

Ugh, Array. This issue makes me feel that the right solution is probably to deprecate it (and newtype) and change Array to a real datatype. That or deprecate the Array datatype entirely; I think basically all use cases are better served by raw-array. I think it's basically the only source use of newtype in the whole runtime library, and no one really uses it other than that. I suppose Array could allow for [] since it can have methods, but I'm not sure that's a great argument for keeping it.

@sorawee do you mind sharing what you were writing when you found this?

sorawee commented 2 months ago

Here's the repaired program written by B Nagy András.

https://code.pyret.org/editor#share=1bVMDO1TN8XX_jlnOIBMeONfMtr-WBg0d&v=0c33ff0

If I'm not mistaken, he is managing https://exercism.org/tracks/pyret, and this is one of the ported problems that he tried out to make sure it's feasible to solve.

EDITED: A couple of other solutions here: https://exercism.org/tracks/pyret/exercises/circular-buffer/solutions

There gotta be a stencil file somewhere, but I couldn't find it.

sorawee commented 2 months ago

Ah, his GitHub handler is @BNAndras.

BNAndras commented 2 months ago

Yup, that’s correct.