Last active
August 29, 2015 14:19
-
-
Save clementi/0ce7361b00318c650486 to your computer and use it in GitHub Desktop.
List the contents of the PATH environment variable in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
import System.FilePath | |
wordsWhen :: (Char -> Bool) -> String -> [String] | |
wordsWhen p s = case dropWhile p s of | |
"" -> [] | |
s' -> w : wordsWhen p s'' | |
where (w, s'') = break p s' | |
main :: IO () | |
main = do | |
path <- getEnv "PATH" | |
mapM_ putStrLn $ wordsWhen (==searchPathSeparator) path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment