Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fromListWithDef diverges when passed an infinite list, for the following reasons: Reason 1: * fromListWithDef calls Data.Primitive.Array.fromListN (bits + 1). fromListN requires that the length of the list that is passed to it is exactly bits + 1. To ensure this, it forces the spine of the list that is passed to it. * The list that is passed to fromListN is generated by go0, which calls go. When xs is infinite, go k xs will be infinite. Therefore, fromListN will throw an error since go0 yields a list longer than bits + 1. Even if we take the first bits + 1 elements of go0 before passing to fromListN, there is another problem. Reason 2: * As fromListN forces the spine, it will compute go 0 xs0, go 1 xs1, ..., go 63 xs63, for some xs0, xs1, ..., xs63. * This in turn requires computing measureOff (2^0) xs0, measureOff (2^1) x1, ..., measureOff (2^63) x63, which is essentially divergent. To avoid these problems, we implement fromListWithDef in terms of fromInfinite. Note that the implementation of fromInfinite is similar to the old implementation of fromListWithDef, except that it doesn't call measureOff, which is the source of the divergence.
- Loading branch information