-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
src/Data/Chimera/Internal.hs
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
Thanks a lot! |
In the implementation of
fromInfinite
, we pass an infinite list toData.Primitive.Array.fromListN (bits + 1)
, butfromListN
expects a list a list of lengthbits + 1
, which results in a runtime error.To fix this, we take the firstbits + 1
of the infinite list before passing tofromListN
.Updated solution: To fix this, we add a check in
go
to break recursion and to ensure that the list that is passed intofromListN
has lengthbits + 1
.Fixes issue #40