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

Seq: make whole/part-container transforms such as fmap strict #11

Open
infinity0 opened this issue Nov 6, 2022 · 2 comments
Open

Seq: make whole/part-container transforms such as fmap strict #11

infinity0 opened this issue Nov 6, 2022 · 2 comments

Comments

@infinity0
Copy link
Member

infinity0 commented Nov 6, 2022

As described in the latest documentation. Possible candidates beyond fmap:

  • scan*
  • update, insertAt, and anything else we might've missed with a similar type signature -> a .. -> (Seq a, *).
  • dynamic constructors e.g. from*, replicate*, iterateN. although the documentation says they are O(n), from a quick reading of the source code it seems this really means "only if someone actually evaluates the whole thing e.g. by printing it", since the lazy parts of the Deep structure stay lazy

Some technical details in haskell/containers#752

@infinity0 infinity0 changed the title Make whole/part-container transforms such as fmap strict Seq: make whole/part-container transforms such as fmap strict Nov 6, 2022
@infinity0
Copy link
Member Author

By sheer luck, in many cases giving a undefined will crash the dynamic constructors, because the periphery of the data structure is forced in the data definition. However we can carefully hack around this luck like this:

ghci> import Data.Strict.Sequence as S
ghci> uf = [1, 1, 1, 1, 1, undefined, 1, 1, 1, 1]
ghci> S.length $ S.fromList uf
10

The last would be expected to fail in a proper strict container, and it does with Vector:

ghci> import Data.Strict.Vector as V
ghci> V.length $ V.fromList uf
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err
  undefined, called at <interactive>:14:22 in interactive:Ghci7

@infinity0
Copy link
Member Author

insertAt might be strict-safe by sheer virtue of having to reconstruct one half of the data structure (it crashed for me with undefined, for all params I thought to test), but it's hard to be sure if this holds for all possible parameters; safest to just stick a ! on the param anyway

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

No branches or pull requests

1 participant