diff options
| -rwxr-xr-x | challenge-028/stuart-little/haskell/ch-1.hs | 21 | ||||
| -rwxr-xr-x | challenge-028/stuart-little/haskell/ch-2.hs | 16 |
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-028/stuart-little/haskell/ch-1.hs b/challenge-028/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..372290f2ed --- /dev/null +++ b/challenge-028/stuart-little/haskell/ch-1.hs @@ -0,0 +1,21 @@ +#!/usr/bin/env runghc + +-- run <script> <file-path> + +import System.Directory (getFileSize,) +import System.Environment (getArgs,) +import System.IO (IOMode( ReadMode ),openFile,) +import qualified Data.ByteString as B +import qualified Data.ByteString.UTF8 as B + +main = do + pth <- getArgs >>= return . head + fs <- getFileSize pth + hand <- openFile pth ReadMode + cont <- B.hGetContents hand + let tp = if elem B.replacement_char $ B.toString cont + then "binary" + else "text" + putStrLn $ if fs==0 then "empty file" + else tp ++ " file" + diff --git a/challenge-028/stuart-little/haskell/ch-2.hs b/challenge-028/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..7111ddee84 --- /dev/null +++ b/challenge-028/stuart-little/haskell/ch-2.hs @@ -0,0 +1,16 @@ +#!/usr/bin/env runghc + +-- run <script> + +import Data.Time (getZonedTime,formatTime,defaultTimeLocale,) +import System.Console.ANSI (clearScreen,cursorUp,) +import System.Time.Extra (sleep,) + +main :: IO () +main = do + clearScreen + cursorUp 1 + tm <- getZonedTime + putStrLn $ formatTime defaultTimeLocale "%T" tm + sleep 1 + main |
