Created
April 28, 2023 04:30
-
-
Save xieyuschen/312619178bd77ee0b454368048bb5b35 to your computer and use it in GitHub Desktop.
execute ls and print the results by 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
{-# 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