Skip to content

Commit

Permalink
#40 Fix fromInfinite error
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
pgujjula authored and Bodigrim committed Apr 12, 2024
1 parent 0c02300 commit ecacbd1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Data/Chimera/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@ fromInfinite = Chimera . fromListN (bits + 1) . go0
where
go0 (x :< xs) = G.singleton x : go 0 xs

go k xs = G.fromListN kk ys : go (k + 1) zs
go k xs =
if k == bits
then []
else G.fromListN kk ys : go (k + 1) zs
where
kk = 1 `shiftL` k
(ys, zs) = Inf.splitAt kk xs
Expand Down

0 comments on commit ecacbd1

Please sign in to comment.