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

filter/filter rules are incorrect #559

Closed
meooow25 opened this issue Feb 14, 2024 · 1 comment · Fixed by #560
Closed

filter/filter rules are incorrect #559

meooow25 opened this issue Feb 14, 2024 · 1 comment · Fixed by #560

Comments

@meooow25
Copy link
Contributor

import qualified Data.Text as T
main = print $ T.filter (const undefined) $ T.filter (const False) $ T.singleton 'a'

Without optimizations, prints

""

With optimizations,

tfilter: Prelude.undefined
CallStack (from HasCallStack):
  undefined, called at tfilter.hs:2:32 in main:Main

text/src/Data/Text.hs

Lines 1660 to 1663 in 456783a

{-# RULES
"TEXT filter/filter -> filter" forall p q t.
filter p (filter q t) = filter (\c -> p c && q c) t
#-}

text/src/Data/Text/Lazy.hs

Lines 1691 to 1694 in 456783a

{-# RULES
"TEXT filter/filter -> filter" forall p q t.
filter p (filter q t) = filter (\c -> p c && q c) t
#-}

The problem is that the predicate of the inner filter is not checked first.

The rule in the stream code is, however, correct

{-# RULES
"STREAM filter/filter fusion" forall p q s.
filter p (filter q s) = filter (\x -> q x && p x) s
#-}

@meooow25
Copy link
Contributor Author

For the record, I happened to notice this in the code. I did not find this out the hard way.

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

Successfully merging a pull request may close this issue.

1 participant