<commit_before>

-- LIST

hint = concat (map f x) ==> concatMap f x
hint "Use one map" = map f (map g x) ==> map (f . g) x
hint = (x !! 0) ==> head x
hint = take n (repeat x) ==> replicate n x
hint = (x ++ concatMap (' ':) y) ==> unwords (x:y)
hint = concat (intersperse " " x) ==> unwords x

-- BOOL

hint = not (a == b) ==> (a /= b)
hint = not (a /= b) ==> (a == b)
hint "Redundant if" = (if a then True else False) ==> a
hint "Redundant if" = (if a then False else True) ==> not a
hint "Redundant if" = (if a then t else (if b then t else f)) ==> if a || b then t else f
hint "Redundant if" = (if a then (if b then t else f) else f) ==> if a && b then t else f
hint "Use if" = case a of {True -> t; False -> f} ==> if a then t else f
hint "Use if" = case a of {True -> t; _ -> f} ==> if a then t else f
hint "Use if" = case a of {False -> f; _ -> t} ==> if a then t else f

-- MONAD

hint = m >>= return . f ==> liftM f m

-- LIST COMP

hint "Use a list comprehension" = (if b then [x] else []) ==> [x | b]

-- SEQ

hint "The seq is redundant" = (x `seq` x) ==> x
hint "The $! is redundant" = (id $! x) ==> x

-- MAYBE

hint = maybe x id  ==> fromMaybe x
hint = maybe False (const True) ==> isJust
hint = maybe True (const False) ==> isNothing


{-
-- more complicated, saved for later

-- head x
head_head err (x:xs) = x
head_head err [] = error err

-- fromJust x
use_fromJust err (Just x) = x
use_fromJust err Nothing = error err


-- fromMaybe def x
use_fromMaybe def (Just x) = x
use_fromMaybe def Nothing = def

-- listMaybe x
use_listMaybe [] = Nothing
use_listMaybe (x:xs) = Just x

-- maybeToList x
use_maybeToList (Just x) = [x]
use_maybeToList Nothing = []

-- mapM_ f x >> y
use_mapM_ f x y = mapM f x >> y


-- map f x
redefined_map = mop
    where
        mop f (x:xs) = f x : mop f xs
        mop f [] = []

-- map<f> x
special_map f = mop
    where
        mop (x:xs) = f x : mop xs
        mop [] = []


-- foldr f z x
special_foldr f z = fold
    where
        fold [] = z
        fold (x:xs) = f x (fold xs)

-- foldl f z x
special_foldl1 f = fold
    where
        fold acc [] = acc
        fold acc (x:xs) = fold (f x acc) xs

special_foldl2 f = fold
    where
        fold [] acc = acc
        fold (x:xs) acc = fold xs (f x acc)<commit_msg>Reformat the tests, remove some that are outdated<commit_after>

-- LIST

hint = concat (map f x) ==> concatMap f x
hint "Use one map" = map f (map g x) ==> map (f . g) x
hint = (x !! 0) ==> head x
hint = take n (repeat x) ==> replicate n x
hint = (x ++ concatMap (' ':) y) ==> unwords (x:y)
hint = concat (intersperse " " x) ==> unwords x

-- BOOL

hint = not (a == b) ==> (a /= b)
hint = not (a /= b) ==> (a == b)
hint "Redundant if" = (if a then True else False) ==> a
hint "Redundant if" = (if a then False else True) ==> not a
hint "Redundant if" = (if a then t else (if b then t else f)) ==> if a || b then t else f
hint "Redundant if" = (if a then (if b then t else f) else f) ==> if a && b then t else f
hint "Use if" = case a of {True -> t; False -> f} ==> if a then t else f
hint "Use if" = case a of {True -> t; _ -> f} ==> if a then t else f
hint "Use if" = case a of {False -> f; _ -> t} ==> if a then t else f

-- MONAD

hint = m >>= return . f ==> liftM f m

-- LIST COMP

hint "Use a list comprehension" = (if b then [x] else []) ==> [x | b]

-- SEQ

hint "The seq is redundant" = (x `seq` x) ==> x
hint "The $! is redundant" = (id $! x) ==> x

-- MAYBE

hint = maybe x id  ==> fromMaybe x
hint = maybe False (const True) ==> isJust
hint = maybe True (const False) ==> isNothing


{-
<TEST>

yes = concat . map f
yes = map f (map g x)
yes = concat.map (\x->if x==e then l' else [x])
yes = f x where f x = concat . map head
yes = concat . map f . g
yes = concat $ map f x
yes = "test" ++ concatMap (' ':) ["of","this"]
yes = concat . intersperse " "
yes = if f a then True else False
yes = if f a then False else True
yes = not (a == b)
yes = not (a /= b)
yes = if a then 1 else if b then 1 else 2
no  = if a then 1 else if b then 3 else 2
yes = a >>= return . id
yes = (x !! 0) + (x !! 2)
yes = if x == e then l2 ++ xs else [x] ++ check_elem xs
yes = if b < 42 then [a] else []

</TEST>
-}


{-
-- more complicated, saved for later

-- map f x
redefined_map = mop
    where
        mop f (x:xs) = f x : mop f xs
        mop f [] = []

-- map<f> x
special_map f = mop
    where
        mop (x:xs) = f x : mop xs
        mop [] = []


-- foldr f z x
special_foldr f z = fold
    where
        fold [] = z
        fold (x:xs) = f x (fold xs)

-- foldl f z x
special_foldl1 f = fold
    where
        fold acc [] = acc
        fold acc (x:xs) = fold (f x acc) xs

special_foldl2 f = fold
    where
        fold [] acc = acc
        fold (x:xs) acc = fold xs (f x acc)
{'fraction_non_alphanumeric': 0.15785036880927292, 'fraction_numerical': 0.003582718651211802, 'mean_word_length': 2.2935461485079807, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5343673', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1833, 'n_words': 815}