Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: How to unnest "do" (Martin Drautzburg) 2. Re: How to unnest "do" (Brent Yorgey) 3. Re: missing ghci, need to install cca (C K Kashyap) 4. Re: missing ghci, need to install cca (Franco) ---------------------------------------------------------------------- Message: 1 Date: Sun, 27 Jan 2013 23:29:18 +0100 From: Martin Drautzburg <martin.drautzb...@web.de> Subject: Re: [Haskell-beginners] How to unnest "do" To: beginners@haskell.org Message-ID: <201301272329.18303.martin.drautzb...@web.de> Content-Type: Text/Plain; charset="iso-8859-15" On Sunday, 27. January 2013 20:43:58 Ertugrul S?ylemez wrote: > Hi there Martin, > > since the nested 'do' makes sense, there is little you can do about it. > However, you can make the code more beautiful and restructure it a bit. > This is how I would have written it: > > import Control.Applicative > import System.Environment > import System.IO > > stats :: String -> String > stats = > unwords . > sequence [show . length . words, > show . length . lines, > show . length] > > main :: IO () > main = do > args <- getArgs > case args of > [fn] -> fmap stats (readFile fn) >>= putStrLn --<---- > _ -> hPutStrLn stderr "Usage: wc FNAME" > > This improves the statistics code slightly, but uses some monadic > machinery you may not be familiar with. Thanks, this looks much nicer and is very inspiring. But let me see if I get this correctly: readFile fn returns IO String I cannot see the String itself, but I can map the stats function over it, which gives me anoter IO String. This works, because every Monad is also a functor. Another way of looking at this is that fmap lifts the String->String function "stats" to (IO String) -> (IO String), Again I cannot see the String inside the IO String, but I can pass it to a function String->IO String, using (>>=) and putStrLn is such a function, which also does what I need. I cannot use the same fmap mechanism ("fmap putStrLn"), because putStrLn is already String -> IO String and fmap would lift both sides of "->". I tried to find another way of passing the IO String to putStrLn, but there aren't many options. If I want to use putStrLn, then I need to get the String out of the IO String. AFAICS (>>=) is the only way to do this (other than do notation). In contrast to fmap, (>>=) lifts only the left side. For the hell of it, I tried to replace putStrLn by a String -> Maybe String function. This does not work and it made me realize, that the signature of (>>=) :: m a -> (a-> m b) -> m b demands that the the Monad "m" is the same all the way through, and only its type parameter can change. And the Applicative import is not really needed. Is this about correct? When I have a program, which accesses stdin and stdout and a database, I suppose I will have to do things like this a lot? Sorry for the long post, but I am getting kindof excieted. ------------------------------ Message: 2 Date: Sun, 27 Jan 2013 17:42:04 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] How to unnest "do" To: beginners@haskell.org Message-ID: <20130127224204.ga26...@seas.upenn.edu> Content-Type: text/plain; charset=iso-8859-1 On Sun, Jan 27, 2013 at 11:29:18PM +0100, Martin Drautzburg wrote: > On Sunday, 27. January 2013 20:43:58 Ertugrul S?ylemez wrote: > > Hi there Martin, > > > > since the nested 'do' makes sense, there is little you can do about it. > > However, you can make the code more beautiful and restructure it a bit. > > This is how I would have written it: > > > > import Control.Applicative > > import System.Environment > > import System.IO > > > > stats :: String -> String > > stats = > > unwords . > > sequence [show . length . words, > > show . length . lines, > > show . length] > > > > main :: IO () > > main = do > > args <- getArgs > > case args of > > [fn] -> fmap stats (readFile fn) >>= putStrLn --<---- > > _ -> hPutStrLn stderr "Usage: wc FNAME" > > > > This improves the statistics code slightly, but uses some monadic > > machinery you may not be familiar with. > > Thanks, this looks much nicer and is very inspiring. > > But let me see if I get this correctly: > > readFile fn returns IO String > > I cannot see the String itself, but I can map the stats function over it, > which gives me anoter IO String. This works, because every Monad is also a > functor. Another way of looking at this is that fmap lifts the String->String > function "stats" to (IO String) -> (IO String), > > Again I cannot see the String inside the IO String, but I can pass it to a > function String->IO String, using (>>=) and putStrLn is such a function, > which > also does what I need. > > I cannot use the same fmap mechanism ("fmap putStrLn"), because putStrLn is > already String -> IO String and fmap would lift both sides of "->". > > I tried to find another way of passing the IO String to putStrLn, but there > aren't many options. If I want to use putStrLn, then I need to get the String > out of the IO String. AFAICS (>>=) is the only way to do this (other than do > notation). In contrast to fmap, (>>=) lifts only the left side. > > For the hell of it, I tried to replace putStrLn by a String -> Maybe String > function. This does not work and it made me realize, that the signature of > (>>=) :: m a -> (a-> m b) -> m b demands that the the Monad "m" is the same > all the way through, and only its type parameter can change. > > And the Applicative import is not really needed. > > Is this about correct? That all sounds right to me! -Brent ------------------------------ Message: 3 Date: Mon, 28 Jan 2013 12:01:53 +0530 From: C K Kashyap <ckkash...@gmail.com> Subject: Re: [Haskell-beginners] missing ghci, need to install cca To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Message-ID: <CAGdT1grWx1SHEmsReGDWF=bF3_sUEPBPZ1upQeRxa=ut6qf...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Hi Franco, I've seen this problem when you do not have ~/.cabal/bin in your path. Can you re-try cabal install Euterpea after adding ~/.cabal/bin in your path. Also, just check if ~/.cabal/bin has cca executable in there or not. Regards, Kashyap On Sat, Jan 26, 2013 at 5:30 PM, Franco <franc...@gmx.com> wrote: > > What version of ghc do you have? I thought the 7.6.1 version > > of ghci for armhf did support a working ghci. > > 7.4.1 (I am running wheezy/sid). > > 7.6.1 is being tested in experimental [1], but debian experimental is > quite a > nightmare for me, I plan to stay on stable as soon as wheezy is released. > > [1] http://packages.debian.org/experimental/ghc > > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130128/48a0f9d6/attachment-0001.htm> ------------------------------ Message: 4 Date: Mon, 28 Jan 2013 09:33:33 +0000 From: Franco <franc...@gmx.com> Subject: [Haskell-beginners] Re: missing ghci, need to install cca To: beginners@haskell.org Message-ID: <20130128093044.GA4680@efikamx> Content-Type: text/plain; charset=us-ascii > Hi Franco, > > I've seen this problem when you do not have ~/.cabal/bin in your path. Can > you re-try cabal install Euterpea after adding ~/.cabal/bin in your path. > Also, just check if ~/.cabal/bin has cca executable in there or not. > Regards, > Kashyap I have added the directory to PATH, unfortunately compile fails with the same error: src/Language/Haskell/TH/Instances.hs:175:18: Template Haskell splice illegal in a stage-1 compiler return (LitE (DoublePrimL (toRational d))) cabal: Error: some packages failed to install: CCA-0.1.3 failed during the building phase. The exception was: ExitFailure 1 demo@efikamx:~/Desktop/media/git/Euterpea$ $ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/demo/.cabal/bin there is no cca executable in ~/.cabal/bin I will try to see if other packages will do. Thanks! -F ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 55, Issue 31 *****************************************