Skip to content

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

Open
@matthewbauer

Description

@matthewbauer

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

Activity

luite

luite commented on Mar 25, 2020

@luite
Member

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Data.JSString.pack breaks when using irrefutable patterns · Issue #128 · ghcjs/ghcjs-base