Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Haskeline and forkIO (Jeff C. Britton)
----------------------------------------------------------------------
Message: 1
Date: Wed, 27 Aug 2014 19:03:49 +0000
From: "Jeff C. Britton" <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Haskeline and forkIO
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
If I modify the code to the suggested form:
let f = runWorker (worker path)
in
do
f
loop
then I get the following compile error
Couldn't match type `IO' with `InputT IO'
Expected type: InputT IO ()
Actual type: IO ()
In a stmt of a 'do' block: f
In the expression:
do { f;
loop }
I have also tried
let f = runWorker (worker path)
in
do
return f
loop
This compiles, but won't run forkIO.
I can't figure out how to get forkIO to run and make the type system happy.
I am going to past the code again, because the line breaks got messed up the
first time.
I have removed the `seq` call though as it simplifies the code a bit.
import Control.Concurrent (forkIO)
import Control.Exception
import qualified Data.ByteString.Lazy as L
import System.Console.Haskeline hiding (handle)
-- Provided by the 'zlib' package on http://hackage.haskell.org/
import Codec.Compression.GZip (compress)
worker :: FilePath -> IO ()
worker path = L.readFile path >>= L.writeFile (path ++ ".gz") . compress
runWorker :: FilePath -> IO()
runWorker path = handle (print :: SomeException -> IO ()) $ do
forkIO (worker path)
return ()
loop :: InputT IO ()
loop = do
maybeLine <- getInputLine "Enter a file to compress> "
case maybeLine of
Nothing -> return () -- user entered EOF
Just "" -> return () -- treat no name as "want to quit"
Just path -> do
return (runWorker path)
loop
main = runInputT defaultSettings loop
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 74, Issue 27
*****************************************