From a9ac58af31c1f793739da9ac9182438b107f184a Mon Sep 17 00:00:00 2001 From: konsumlamm Date: Tue, 21 Jan 2025 19:37:21 +0100 Subject: [PATCH] Fix `Data.List.isInfixOf` --- lib/Data/List.hs | 2 +- tests/ListTest.hs | 12 +++++++----- tests/ListTest.ref | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Data/List.hs b/lib/Data/List.hs index 354c7166..5c464ac5 100644 --- a/lib/Data/List.hs +++ b/lib/Data/List.hs @@ -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) diff --git a/tests/ListTest.hs b/tests/ListTest.hs index 6776b108..0f962b47 100644 --- a/tests/ListTest.hs +++ b/tests/ListTest.hs @@ -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] diff --git a/tests/ListTest.ref b/tests/ListTest.ref index dec1f87f..464add01 100644 --- a/tests/ListTest.ref +++ b/tests/ListTest.ref @@ -2,3 +2,4 @@ 24 True False +True