Skip to content

Instantly share code, notes, and snippets.

@xieyuschen
Created April 28, 2023 04:30
Show Gist options
  • Save xieyuschen/312619178bd77ee0b454368048bb5b35 to your computer and use it in GitHub Desktop.
Save xieyuschen/312619178bd77ee0b454368048bb5b35 to your computer and use it in GitHub Desktop.
execute ls and print the results by Haskell
{-# LANGUAGE BlockArguments #-}
import System.Process
import Data.Text.IO (hGetLine)
import GHC.IO.Handle (isEOF, hGetLine)
import GHC.IO.Handle.Types (Handle)
import Data.Type.Equality (outer)
main :: IO ()
main = do
(_, out , _, _) <- createProcess (proc "ls" []){ std_out = CreatePipe }
myLoop out
myLoop :: Maybe Handle -> IO ()
myLoop input = do
done <- isEOF
if done
then return ()
else do
let tmp = GHC.IO.Handle.hGetLine <$> input
case tmp of
Nothing -> return ()
Just x -> do
x >>= putStrLn
myLoop input
-- a -> m b -> m a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment