Alex's Weblog

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Alătură-te lângă 1 urmăritor

  • Noiembrie 2010
    L M M M V S D
    « Oct   Dec »
    1234567
    891011121314
    15161718192021
    22232425262728
    2930  

Recursively list directories in Haskell

Posted by alecs1 pe 2010-11-18

import Directory

myVisit :: String -> IO [String]
myVisit path = do
    isFile <- doesFileExist path
    isDirectory <- doesDirectoryExist path
    print path
    if (path == ".") || (path == "..")
        then return []
        else if isFile
          then return [path]
          else if isDirectory
            then do
                unfilteredContents  x /= "." && x /= "..") unfilteredContents
                visitedDirectories <- mapM myVisit (map ((path ++ "/") ++) contentList)
                return (concat visitedDirectories)
            else return []

This code is the result of spending some good hours in the middle of the night, with lots of input from the very patient guys on the #haskell channel from irc.freenode.net. Very interesting are the bugs of the code and what happens in functions using this code. This Haskell really puts me to work. But that next time.

Lasă un răspuns

Completează mai jos detaliile despre tine sau dă clic pe un icon pentru autentificare:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s

 
%d blogeri au apreciat asta: