aboutsummaryrefslogtreecommitdiff
path: root/challenge-107
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-107')
-rwxr-xr-xchallenge-107/stuart-little/haskell/ch-1.hs16
-rwxr-xr-xchallenge-107/stuart-little/haskell/ch-2.hs25
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-107/stuart-little/haskell/ch-1.hs b/challenge-107/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..25ff4054f6
--- /dev/null
+++ b/challenge-107/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script>
+
+import Data.List.Utils (join)
+import System.Environment (getArgs)
+import Text.Printf (printf)
+
+fst3 :: [(Int, (Int,Int))]
+fst3 = [(100,(4,1210)),(136,(4,2020)),(1425,(5,21200))]
+
+fmt :: (Int,(Int,Int)) -> String
+fmt (nr,(b,nrb)) = printf "Base 10: %d\nBase %d: %d" nr b nrb
+
+main = do
+ putStrLn $ join "\n\n" $ map fmt fst3
diff --git a/challenge-107/stuart-little/haskell/ch-2.hs b/challenge-107/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..09f248d16d
--- /dev/null
+++ b/challenge-107/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,25 @@
+#!/usr/bin/env runghc
+
+{--
+run <script> <module name, e.g. Data.List>
+the module must be in your search path
+defaults to Data.List if you pass no arguments
+--}
+
+{-# LANGUAGE OverloadedStrings #-}
+import Safe (headDef)
+import Shelly
+import System.Environment (getArgs)
+import qualified Data.Text as T
+
+mdl :: IO String
+mdl = getArgs >>= return . headDef "Data.List"
+
+runShelly :: String -> IO ()
+runShelly mdl = shelly $ silently $ do
+ out <- run "ghc" ["-e", T.pack (":browse " ++ mdl)]
+ let lns = T.lines out
+ liftIO $ mapM_ (putStrLn .T.unpack) $ lns
+
+main :: IO ()
+main = mdl >>= runShelly