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. do notation, pattern matching, if, & case (Vale Cofer-Shabica)
2. Re: do notation, pattern matching, if, & case (Brandon Allbery)
3. Re: do notation, pattern matching, if, & case
(Vale Cofer-Shabica)
4. Re: 2014 haskell cabal update hangs on mac (Alexandre Lucchesi)
5. Haskeline and forkIO (Jeff C. Britton)
6. Re: [Haskell-cafe] 2014 haskell cabal update hangs on mac
(Madhu Babu)
----------------------------------------------------------------------
Message: 1
Date: Tue, 26 Aug 2014 14:16:45 -0400
From: Vale Cofer-Shabica <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] do notation, pattern matching, if, & case
Message-ID:
<caazfv4slqqy0+73r-gyc+hgjdab7-hfstvqwbkkken7zswd...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
I'm working on a cli program where I'd like to take input from a file
or stdin. I've managed to get my program to work but thought my
dispatch mechanism could be simplified. I use a scheme along the lines
of f in the following minimal example, which compiles. However, if I
try to use f' or f'', I get parse errors. Three questions:
* Is there a better way of doing this
* Are stylistic changes to f really called for?
* How can/ought I correct my syntax errors?
Many thanks,
vale
>module MinimalExample where
>import System.IO (getContents)
>f :: String -> IO ()
>f "-" = do
> s <- getContents
> putStrLn s
>f file = do
> s <- readFile file
> putStrLn s
>-- f' :: String -> IO ()
>-- f' file = do
>-- if file == "-"
>-- then s <- getContents
>-- else s <- readFile file
>-- putStrLn s
>-- f'' :: String -> IO ()
>-- f'' file = do
>-- case file of
>-- "-" -> s <- getContents
>-- _ -> s <- readFile file
>-- putStrLn s
--
vale cofer-shabica
[email protected]
------------------------------
Message: 2
Date: Tue, 26 Aug 2014 14:23:35 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] do notation, pattern matching, if, &
case
Message-ID:
<cakfcl4vezjajfqvhjceq2htehtuk5fze3lzxsrwtkiiyu42...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue, Aug 26, 2014 at 2:16 PM, Vale Cofer-Shabica <
[email protected]> wrote:
> However, if I try to use f' or f'', I get parse errors. Three questions:
>
> * Is there a better way of doing this
> * Are stylistic changes to f really called for?
> * How can/ought I correct my syntax errors?
>
if and case are expressions. As such they are not part of the outer "do"'s
syntax; you would need a new "do" in each one. This will make more sense if
you study how "do" is converted to uses of the (>>) and (>>=) operators.
Additionally you can't just use "s <- getContents" like that, since (a) "s"
will go out of scope, abnd (b) with nothing following, it expands to a
syntax error ("getContents >>= \s ->" with nothing after the "->"). Since
if and case are expressions, you need to produce a result from them and
bind it at the top level. So you really want something like:
f' :: String -> IO ()
f' file = do
s <- if file == "-"
then getContents
else readFile file
putStrLn s
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140826/4b0dba3e/attachment-0001.html>
------------------------------
Message: 3
Date: Tue, 26 Aug 2014 14:47:25 -0400
From: Vale Cofer-Shabica <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] do notation, pattern matching, if, &
case
Message-ID:
<CAAzfV4Q2yCwxoyJmCwEa484Me-=o1ngj8qmcelhz8+ors50...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Thank you!
I was able to re-write the case-of version as well so it compiles too.
I'll read up on de-sugaring do-notation.
-vale
--
vale cofer-shabica
[email protected]
401.267.8253
On Tue, Aug 26, 2014 at 2:23 PM, Brandon Allbery <[email protected]> wrote:
> On Tue, Aug 26, 2014 at 2:16 PM, Vale Cofer-Shabica
> <[email protected]> wrote:
>>
>> However, if I try to use f' or f'', I get parse errors. Three questions:
>>
>> * Is there a better way of doing this
>> * Are stylistic changes to f really called for?
>> * How can/ought I correct my syntax errors?
>
>
> if and case are expressions. As such they are not part of the outer "do"'s
> syntax; you would need a new "do" in each one. This will make more sense if
> you study how "do" is converted to uses of the (>>) and (>>=) operators.
>
> Additionally you can't just use "s <- getContents" like that, since (a) "s"
> will go out of scope, abnd (b) with nothing following, it expands to a
> syntax error ("getContents >>= \s ->" with nothing after the "->"). Since if
> and case are expressions, you need to produce a result from them and bind it
> at the top level. So you really want something like:
>
> f' :: String -> IO ()
> f' file = do
> s <- if file == "-"
> then getContents
> else readFile file
> putStrLn s
>
> --
> brandon s allbery kf8nh sine nomine associates
> [email protected] [email protected]
> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 4
Date: Tue, 26 Aug 2014 16:03:47 -0300
From: Alexandre Lucchesi <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] 2014 haskell cabal update hangs on
mac
Message-ID:
<cagqbpew9c_jtnwrzjmefnegsinysux8rd98bpkvmxe5k-cv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'm not sure if the following steps will solve your problems nor if they're
all required, but maybe you should try:
- Remove "~/.ghc" and "~/.cabal" directories.
- Check if "~/.cabal/bin" is in your path and add it otherwise.
- Run "cabal update".
I prefer using Homebrew to install the Haskell Platform and current version
is still 2013 (7.6.3 ghc), so I can't give further advices.
2014-08-26 1:51 GMT-03:00 Madhu Babu <[email protected]>:
> I initially installed haskell platform ( 2013 version; 7.6.3 ghc ) on my
> mac. Everything was working great. Just now saw the haskell platform
> website again and found new version was released ( Haskell Platform
> 2014.2.0.0 for Mac OS X, 64bit ). I installed it, and un-installed the
> older version using uninstall-hs.
>
> Now when i type "cabal" or "cabal update" on my terminal, it hangs.
> Actually when i look into Activity Monitor, i can see that it is invoking
> some "sh script & possibly some find command" infinitely. I initially guess
> may be it is building some indexes. but it has been running for an hr or so.
>
> I have Xcode 5, gcc and other command line tools installed properly
>
> Please advice. I cannot install any other package using cabal.
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
alexandre lucchesi
*Perfection is achieved, not when there is nothing more to add, but when
there is nothing left to take away!*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140826/284ff734/attachment-0001.html>
------------------------------
Message: 5
Date: Tue, 26 Aug 2014 22:07:14 +0000
From: "Jeff C. Britton" <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] Haskeline and forkIO
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
I am trying to modify an example in RealWorldHaskell from Chapter 24.
The example is the first code snippet labeled -- file: ch24/Compressor.hs
I am trying to replace the use of Readline with Haskeline.
In my code the forkIO thread does not run.
I guessed that since the result of the worker thread was thrown away that
perhaps laziness was the problem.
So, I attempted to use `seq`, but that does not work either.
I am able to run the RealWorldHaskell example.
I am using GHC 7.8.3.
I have tried runhaskell with and without the -threaded option and on both Linux
and Windows 7.
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)
-- Read the file, compress the data, write the compressed data
worker :: FilePath -> IO ()
worker path = L.readFile path >>= L.writeFile (path ++ ".gz") . compress
-- Run the worker on a new thread
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 ->
let f = runWorker path
in
f `seq` do
return f
loop
main = runInputT defaultSettings loop
------------------------------
Message: 6
Date: Tue, 26 Aug 2014 19:58:20 -0400
From: Madhu Babu <[email protected]>
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: [Haskell-beginners] [Haskell-cafe] 2014 haskell cabal
update hangs on mac
Message-ID:
<CALh-VV6gLG3iuE=0CMKp8XygNt2XsN9ngyXzrgX=wywt0te...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You are right. It worked for me now. Earlier, i deleted only
/Library/Hashell, ~/.cabal & one more similar dir. Looks like there are lot
of directories ( & more importantly broken symlinks which were still
pointing to old Library ).
Once i deleted all of them, it worked.
Thanks again for the advice.
On Tue, Aug 26, 2014 at 4:23 PM, S D Swierstra <[email protected]>
wrote:
> I suffered from the same phenomenon. I carefully removed everything which
> smelled of ghc, including .ghc in my home directory and many spurious
> aliases. That cured the problem,
>
> Doaitse
>
>
> On 26 Aug 2014, at 6:51 , Madhu Babu <[email protected]> wrote:
>
> I initially installed haskell platform ( 2013 version; 7.6.3 ghc ) on my
> mac. Everything was working great. Just now saw the haskell platform
> website again and found new version was released ( Haskell Platform
> 2014.2.0.0 for Mac OS X, 64bit ). I installed it, and un-installed the
> older version using uninstall-hs.
>
> Now when i type "cabal" or "cabal update" on my terminal, it hangs.
> Actually when i look into Activity Monitor, i can see that it is invoking
> some "sh script & possibly some find command" infinitely. I initially guess
> may be it is building some indexes. but it has been running for an hr or so.
>
> I have Xcode 5, gcc and other command line tools installed properly
>
> Please advice. I cannot install any other package using cabal.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140826/6f6b406a/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 74, Issue 24
*****************************************