Skip to content

Instantly share code, notes, and snippets.

@clementi
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clementi/0ce7361b00318c650486 to your computer and use it in GitHub Desktop.
Save clementi/0ce7361b00318c650486 to your computer and use it in GitHub Desktop.
List the contents of the PATH environment variable in Haskell
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