Talk:Haskell programming tips/Discussion
I'm hoping to post this here as an attempt to clarify some problems that have been talked about in the Programming tips.
First one to talk about is the claim "The way linify is currently defined, it produces 4 GHC warnings. I do not even know how to get rid of 2 of them."
I'm not sure what flags the writer is compiling with but I had a similar issue.
Here's a slightly modified version which does not cause compiler warnings/errors.
foreach2 :: Monad m => [a] -> [b] -> (a -> b -> m c) -> m () foreach2 xs ys f = zipWithM_ f xs ys linify :: [String] -> IO () linify lines' = foreach2 [(1::Int)..]lines' $ \n line -> unless (null line) $ putStrLn $ shows n $ showString ": " $ show line main :: IO () main = do let ls = lines "Testing\n1\nTwo\n\n4" print ls linify ls
P.S. I'm compiling this with ghc -Wall -Werror -O.
My version information is: Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version 7.10.3