Skip to content

Commit

Permalink
Fix Data.List.isInfixOf
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumlamm committed Jan 21, 2025
1 parent bdd3807 commit a9ac58a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Data/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ isInfixOf :: forall a . Eq a => [a] -> [a] -> Bool
isInfixOf = isInfixOfBy (==)

isInfixOfBy :: forall a . (a -> a -> Bool) -> [a] -> [a] -> Bool
isInfixOfBy eq cs ds = any (isPrefixOfBy eq cs) (inits ds)
isInfixOfBy eq cs ds = any (isPrefixOfBy eq cs) (tails ds)

splitAt :: forall a . Int -> [a] -> ([a], [a])
splitAt n xs = (take n xs, drop n xs)
Expand Down
12 changes: 7 additions & 5 deletions tests/ListTest.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module ListTest(module ListTest) where
import Prelude

import Data.List

main :: IO ()
main = do
putStrLn $ show $ sum [1,2,3::Int]
putStrLn $ show $ product [1,2,3,4::Int]
putStrLn $ show $ and [True]
putStrLn $ show $ and [True, False]
print $ sum [1, 2, 3 :: Int]
print $ product [1, 2, 3, 4 :: Int]
print $ and [True]
print $ and [True, False]
print $ [2] `isInfixOf` [1, 2, 3 :: Int]
1 change: 1 addition & 0 deletions tests/ListTest.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
24
True
False
True

0 comments on commit a9ac58a

Please sign in to comment.