Skip to content

Semigroup.py fails when trying to join array and tuple #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mikesol opened this issue Jun 24, 2020 · 2 comments
Open

Semigroup.py fails when trying to join array and tuple #2

mikesol opened this issue Jun 24, 2020 · 2 comments
Assignees

Comments

@mikesol
Copy link

mikesol commented Jun 24, 2020

Hi!

I've noticed that sometimes, the function concatArray in Semigroup.py receives a list and a tuple to concat, which results in the following error:

TypeError: can only concatenate tuple (not "list") to tuple

In my local copy of the library, I've changed it to this just to get things working:

def concatArray(xs):
    def _1(ys):
        foo = tuple(xs)
        bar = tuple(ys)
        return bar if not foo else foo if not bar else foo + bar
    return _1

But that feels a bit off.

Is there a general policy for tuples vs lists in python-land? For example, in Data.Functor in the prelude, I see that tuple is used, but in Data.Array I see that list is used.

If tuples and lists can be used interchangeably, then I'd make sure that the concat operator is changed to something like the code above.

@thautwarm
Copy link
Member

Hello, thanks a lot for this issue.

I think the problem is not from concatArray, the bug should be an array is transformed into a python list, but it should be a tuple.

Is there a general policy for tuples vs lists in python-land? For example, in Data.Functor in the prelude, I see that tuple is used, but in Data.Array I see that list is used.

Yes, there is a document: https://github.com/purescript-python/purescript-python/blob/master/Interops.md

I think we have incorrectly made the Python FFI interfaces for Data.Array.

@Hong-Xiang This should be assigned to you, but if you are busy you could tell me where the incorrect codes are, I can make a fix.

@mikesol I'm sorry that we haven't reviewed some ffi libraries made in last months, including "purescript-arrays.py".

@mikesol
Copy link
Author

mikesol commented Jun 30, 2020

I would recommend keeping a conversion to tuple and issuing a warning if something is not a tuple. As people add more packages to the FFI, it may be difficult to enforce the use of tuples, and having it crash here makes the system more fragile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants