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

Data.JSString.pack breaks when using irrefutable patterns #128

Open
matthewbauer opened this issue Dec 4, 2019 · 1 comment
Open

Data.JSString.pack breaks when using irrefutable patterns #128

matthewbauer opened this issue Dec 4, 2019 · 1 comment

Comments

@matthewbauer
Copy link
Contributor

matthewbauer commented Dec 4, 2019

Using Data.JSString.pack gives incorrect results. For example:

import Data.JSString (pack)

main :: IO ()
main = print $ pack $ fst $ foldr (select (== 'a')) ([], []) "ababababa" -- "a"
  where
    -- taken from Data.OldList
    select p x ~(ts, fs) | p x       = (x:ts, fs  )
                         | otherwise = (ts  , x:fs)

Outputs "a", and it should output "aaaaa". But if we remove the ~ for irrefutable patterns, we get correct results:

import Data.JSString (pack)

main :: IO ()
main = print $ pack $ fst $ foldr (select (== 'a')) ([], []) "ababababa" -- "aaaaa"
  where
    -- taken from Data.OldList
    select p x (ts, fs) | p x       = (x:ts, fs  )
                        | otherwise = (ts  , x:fs)

I believe this issue has something to do with GHCJS packing the lazy String too early, before the fold is complete.

/cc @eskimor @luite

@luite
Copy link
Member

luite commented Mar 25, 2020

I think this may be a bug related to the handling of selector thunks. It looks like they're not always correctly updated

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

2 participants