Skip to content
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

Fix fromInfinite error #41

Merged
merged 2 commits into from
Apr 12, 2024
Merged

Fix fromInfinite error #41

merged 2 commits into from
Apr 12, 2024

Conversation

pgujjula
Copy link
Contributor

@pgujjula pgujjula commented Apr 12, 2024

In the implementation of fromInfinite, we pass an infinite list to Data.Primitive.Array.fromListN (bits + 1), but fromListN expects a list a list of length bits + 1, which results in a runtime error.

To fix this, we take the first bits + 1 of the infinite list before passing to fromListN.

Updated solution: To fix this, we add a check in go to break recursion and to ensure that the list that is passed into fromListN has length bits + 1.


Fixes issue #40

@pgujjula pgujjula marked this pull request as ready for review April 12, 2024 02:00
This was referenced Apr 12, 2024
@@ -568,7 +568,7 @@ fromInfinite
:: G.Vector v a
=> Infinite a
-> Chimera v a
fromInfinite = Chimera . fromListN (bits + 1) . go0
fromInfinite = Chimera . fromListN (bits + 1) . take (bits + 1) . go0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not produce more than bits + 1 elements in the first place? I imagine a check in go to break recursion could help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, I've updated the PR accordingly.

In the implementation of fromInfinite, we pass an infinite list to
Data.Primitive.Array.fromListN (bits + 1), but fromListN expects a list
a list of length (bits + 1), which results in a runtime error.

To fix this, we add a check in go to break recursion and to ensure that
the list that is passed into fromListN has length (bits + 1).
@Bodigrim Bodigrim merged commit ecacbd1 into Bodigrim:master Apr 12, 2024
13 checks passed
@Bodigrim Bodigrim linked an issue Apr 12, 2024 that may be closed by this pull request
@Bodigrim
Copy link
Owner

Thanks a lot!

@pgujjula pgujjula deleted the fix-fromInfinite branch April 12, 2024 19:58
@Bodigrim
Copy link
Owner

Released in https://hackage.haskell.org/package/chimera-0.4.1.0

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

Successfully merging this pull request may close these issues.

fromInfinite errors
2 participants