Added Spew - a silly little toy filter that reads all of StdIn and then forever writes the lines found.
authordavid@mel
Sat Apr 26 15:01:54 2008 +0100 (4 months ago)
changeset 26fc66d43099d
parent 1b5da607f5ca4
child 3b744d274f675
Added Spew - a silly little toy filter that reads all of StdIn and then forever writes the lines found.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/haskell/Spew.hs Sat Apr 26 15:01:54 2008 +0100
@@ -0,0 +1,20 @@
+module Main where
+
+import qualified Data.Sequence as Sequence
+import System.Random
+import qualified Data.ByteString as B
+import Data.ByteString (ByteString)
+import Control.Monad
+
+getLines :: IO [ByteString]
+getLines = catch tryGetLines (const $ return [])
+ where tryGetLines = do line <- B.getLine
+ lines <- getLines
+ return $ line : lines
+
+main = do lines <- liftM Sequence.fromList getLines
+ gen <- newStdGen
+ let indices = randomRs (0, Sequence.length lines - 1) gen
+ sequence . map (B.putStrLn . Sequence.index lines) $ indices
+
+