module Data.Tuple.Example where import qualified Data.Tuple.Lazy as Lazy import qualified Data.Tuple.Strict as Strict import Data.List.HT (sieve, ) partitionLazy :: (a -> Bool) -> [a] -> ([a], [a]) partitionLazy :: forall a. (a -> Bool) -> [a] -> ([a], [a]) partitionLazy a -> Bool p = forall (t :: * -> *) a b. Foldable t => (a -> b -> b) -> b -> t a -> b foldr (\a x -> (if a -> Bool p a x then forall a c b. (a -> c) -> (a, b) -> (c, b) Lazy.mapFst else forall b c a. (b -> c) -> (a, b) -> (a, c) Lazy.mapSnd) (a xforall a. a -> [a] -> [a] :)) ([], []) partitionStrict :: (a -> Bool) -> [a] -> ([a], [a]) partitionStrict :: forall a. (a -> Bool) -> [a] -> ([a], [a]) partitionStrict a -> Bool p = forall (t :: * -> *) a b. Foldable t => (a -> b -> b) -> b -> t a -> b foldr (\a x -> (if a -> Bool p a x then forall a c b. (a -> c) -> (a, b) -> (c, b) Strict.mapFst else forall b c a. (b -> c) -> (a, b) -> (a, c) Strict.mapSnd) (a xforall a. a -> [a] -> [a] :)) ([], []) mainPartitionRuns :: IO () mainPartitionRuns :: IO () mainPartitionRuns = forall a. Show a => a -> IO () print forall a b. (a -> b) -> a -> b $ forall a. (a -> Bool) -> [a] -> ([a], [a]) partitionLazy (forall a. Ord a => a -> a -> Bool >=Int 0) forall a b. (a -> b) -> a -> b $ forall a. a -> [a] repeat (Int 0::Int) mainPartitionBlocks :: IO () mainPartitionBlocks :: IO () mainPartitionBlocks = forall a. Show a => a -> IO () print forall a b. (a -> b) -> a -> b $ forall a. (a -> Bool) -> [a] -> ([a], [a]) partitionStrict (forall a. Ord a => a -> a -> Bool >=Int 0) forall a b. (a -> b) -> a -> b $ forall a. a -> [a] repeat (Int 0::Int) printSomeChars :: (Show a) => a -> IO () printSomeChars :: forall a. Show a => a -> IO () printSomeChars = String -> IO () putStrLn forall b c a. (b -> c) -> (a -> b) -> a -> c . forall a. Int -> [a] -> [a] sieve Int 100000 forall b c a. (b -> c) -> (a -> b) -> a -> c . forall a. Show a => a -> String show mainMemoryOk :: IO () mainMemoryOk :: IO () mainMemoryOk = forall a. Show a => a -> IO () printSomeChars forall a b. (a -> b) -> a -> b $ forall b c a. (b -> c) -> (a, b) -> (a, c) Strict.mapSnd (Int 1forall a. Num a => a -> a -> a +) forall a b. (a -> b) -> a -> b $ (forall a. (a -> a) -> a -> [a] iterate (Int 1forall a. Num a => a -> a -> a +) (Int 0::Int), Int 0::Int) mainMemoryLeak :: IO () mainMemoryLeak :: IO () mainMemoryLeak = forall a. Show a => a -> IO () printSomeChars forall a b. (a -> b) -> a -> b $ forall b c a. (b -> c) -> (a, b) -> (a, c) Lazy.mapSnd (Int 1forall a. Num a => a -> a -> a +) forall a b. (a -> b) -> a -> b $ (forall a. (a -> a) -> a -> [a] iterate (Int 1forall a. Num a => a -> a -> a +) (Int 0::Int), Int 0::Int)