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 * Add a check in go to break recursion and ensure that the list that is passed to fromListN has length (bits + 1). * Rearrange how we compute go, so that measureOff is not forced while forcing the spine of go. # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Apr 11 18:55:38 2024 -0700 # # On branch fix-fromListWithDef # Your branch is up to date with 'origin/fix-fromListWithDef'. # # Changes to be committed: # modified: src/Data/Chimera/Internal.hs # # Untracked files: # .stack-work/ # stack.yaml.lock #
- Loading branch information