aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-21 22:57:40 +0000
committerGitHub <noreply@github.com>2021-01-21 22:57:40 +0000
commit57bef4593439c3e0407e6ce96ed8cfd25f15aef6 (patch)
treeea208cf64c5f60d6aa337d6b20d8fbd44ee379f1
parent864fef4dd465d56f2fc5a0dcf5fd39c55c34fedf (diff)
parent4a0cbd42c5089a5bd7b5393c88de52464bf2a389 (diff)
downloadperlweeklychallenge-club-57bef4593439c3e0407e6ce96ed8cfd25f15aef6.tar.gz
perlweeklychallenge-club-57bef4593439c3e0407e6ce96ed8cfd25f15aef6.tar.bz2
perlweeklychallenge-club-57bef4593439c3e0407e6ce96ed8cfd25f15aef6.zip
Merge pull request #3333 from stuart-little/stuart-little_028_haskell
1st commit on 028_haskell
-rwxr-xr-xchallenge-028/stuart-little/haskell/ch-1.hs21
-rwxr-xr-xchallenge-028/stuart-little/haskell/ch-2.hs16
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