Skip to content

Instantly share code, notes, and snippets.

View mbixby's full-sized avatar

Michal Obrocnik mbixby

View GitHub Profile
-- parseExpr :: something -> Either ParseError Expression
convert :: String -> Either String String
convert input = case parseExpr input of
Left err -> Left $ show err
Right x -> Right $ show x
-- Want:
convert = magicfunction show $ parseExpr
@mbixby
mbixby / gist:2359042
Created April 11, 2012 12:29
Translate directory tree to a tree
data Tree a = Leaf a | Node a [Tree a]
scanDir :: String -> IO (Tree String)
scanDir path = do
contents <- getDirectoryContents path `catch` const (return [])
let files = sort . filter (`notElem` [".", ".."]) $ contents
let pathsAndFiles = zip (repeat path) files
tree <- forM pathsAndFiles $ \(path, file) -> do
isDirectory <- doesDirectoryExist path
if isDirectory