News for hackers. Stuff that matters.
Re:What Compsci textbooks don't tell you: Real world code sucks by danidiaz on Saturday December 22, 2012 @09:46AM (#4956667)
For printf debugging you can use the "trace" function from Debug.Trace.

A "first n files that don't exist" function could be something like:

nexist :: Int -> [FilePath] -> IO [FilePath]

nexist n l = take n . map fst . filter (not.snd) . zip l <$> mapM doesFileExist l

Re:What Compsci textbooks don't tell you: Real world code sucks by Maro on Saturday December 22, 2012 @11:30AM (#4956853)
I hope you don't take offense at what I'm about to say, but the code snippet you provided is not maintainable in the sense of not being readable. It sacrifices maintainability for cleverness. As someone above pointed out, sometimes it's better to write 5 lines instead of 2 lines.

We don't write code primarily for the compiler, if we would then we wouldn't be having this discussion because the compiler doesn't mind spaghetti. We write code for the next guy who will try to read, understand and modify the code. As an experienced programmer I can tell you, but you probably know anyway, that in all languages you can write very concise but completely incomprehensible snippets which even you won't understand in 2 weeks.

Re:What Compsci textbooks don't tell you: Real world code sucks by mifrai on Saturday December 22, 2012 @04:52PM (#4957602)
Honestly, I don't think danidiaz was trying to be clever so much as not knowing about the existence of filterM. A good chunk of the code was just an implementation of it:

    filterM' f xs = map fst . filter snd . zip xs <$> mapM f xs
So, given filterM, the code would have looked like

    nexist n xs = take n <$> filterM (fmap not . doesFileExist) xs
Which doesn't look clever at all and it's fairly easy to understand.
Re:What Compsci textbooks don't tell you: Real world code sucks by danidiaz on Sunday December 23, 2012 @04:21AM (#4959054)
Yeah, I had forgotten about filterM.

By the way, I like the (fmap not . doesFileExist) bit. It´s cleaner and less cluttered than (\f -> doesFileExist f >>= return . not)

Re:What Compsci textbooks don't tell you: Real world code sucks by Maro on Sunday December 23, 2012 @03:41AM (#4958993)
Cool, thanks!