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:  Re: Count how often a menu has been selected (Felipe Lessa)
   2. Re:  Sidebar to variables (Dean Herington)
   3.  Question on monads and laziness (Lakshmi Narasimhan Vaikuntam)
   4.  Re: uses of random number generators (Heinrich Apfelmus)
   5.  Getting the Takusen example code to compile -    failed import
      problem (Daniel Everett)
   6. Re:  Question on monads and laziness (Dean Herington)
   7. RE:  Getting the Takusen example code to compile  -failed
      import problem (Bayley, Alistair)


----------------------------------------------------------------------

Message: 1
Date: Sat, 25 Jul 2009 22:52:24 -0300
From: Felipe Lessa <felipe.le...@gmail.com>
Subject: Re: [Haskell-beginners] Re: Count how often a menu has been
        selected
To: beginners@haskell.org
Message-ID: <20090726015224.ga9...@kira.casa>
Content-Type: text/plain; charset=us-ascii

On Sat, Jul 25, 2009 at 08:22:33PM +0200, Bernhard Lehnert wrote:
> this works great except for the "print a" part which I replaced by:
>
> b <- readIORef a
> print b

Woops, sorry :).  Tip: most haskellers would prefer either

    readIORef a >>= print

or

    print =<< readIORef a

even if you are already in a 'do' block.

--
Felipe.


------------------------------

Message: 2
Date: Sat, 25 Jul 2009 21:53:29 -0400
From: Dean Herington <heringtonla...@mindspring.com>
Subject: Re: [Haskell-beginners] Sidebar to variables
To: Duke Normandin <dukeofp...@ml1.net>,        Haskell Beginners
        <Beginners@haskell.org>
Message-ID: <a06240800c691674b3...@[192.168.1.100]>
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

At 7:42 AM -0600 7/25/09, Duke Normandin wrote:
>My recent questions concerning "variables" spawned this observation:
>
>I take it that programming a solution using a functional language like
>Haskell is really about "linking" a series of functions from which a
>  solution is derived.
>
>It seems to me that this approach would naturally encourage the use of
>the "bottom-up" method of program development. I mean, breaking the
>task down to the smallest possible segments, and then writing a function
>for each segment. Refactoring the task until the smallest segments are
>achieved. Very much like what I learned about programming in Forth (they
>use the term "words" to mean "function")
>
>Am I on the right track here, in my view of the "Haskell approach" to
>programming solutions?
>--
>duke

Yes, indeed.  Haskell, like Forth but probably even more so, makes it 
easy and profitable to program small pieces that can be combined in 
ever-larger chunks.

Dean


------------------------------

Message: 3
Date: Sun, 26 Jul 2009 09:23:33 +0530
From: Lakshmi Narasimhan Vaikuntam <lakshminaras2...@gmail.com>
Subject: [Haskell-beginners] Question on monads and laziness
To: Beginners@haskell.org
Message-ID:
        <3cca9ddb0907252053u26db814et2eead20254a0e...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello
I am studying Real World Haskell chapter 9. Here is a snippet of code

data Info = Info {
      infoPath :: FilePath
    , infoPerms :: Maybe Permissions
    , infoSize :: Maybe Integer
    , infoModTime :: Maybe ClockTime
    } deriving (Eq, Ord, Show)

getInfo :: FilePath -> IO Info

-- file: ch09/ControlledVisit.hs
traverse order path = do
    names <- getUsefulContents path
    contents <- mapM getInfo (path : map (path </>) names)
    liftM concat $ forM (order contents) $ \info -> do
      if isDirectory info && infoPath info /= path
        then traverse order (infoPath info)
        else return [info]

getUsefulContents :: FilePath -> IO [String]
getUsefulContents path = do
    names <- getDirectoryContents path
    return (filter (`notElem` [".", ".."]) names)

isDirectory :: Info -> Bool
isDirectory = maybe False searchable . infoPerms

When I read about IO in the previous chapter, I learnt that reading a file
can be done lazily.
Here my doubt is that whether the expression "order contents" would generate
a list of directory contents (held in memory) for use in forM construct.
Because in a subsequent para, I find this line.

"If we are traversing a directory containing 100,000 files of which we care
about three, we'll allocate a 100,000-element list before we have a chance
to trim it down to the three we really want"


Wouldn't laziness ensure that in the traverse function, when iterating
over directory contents using the list generated by "order contents",
it will generate just one element at a time and then free the memory
for that entry immediately since we are not using the referencing list
anymore in the rest of the function.

Not sure whether I have understood the concept of laziness w.r.t
monads correctly. Please clarify my doubts with regard to the code
snippet.

Thanks for your time.

-- 
Regards
Lakshmi Narasimhan T V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090725/d58439a0/attachment-0001.html

------------------------------

Message: 4
Date: Sun, 26 Jul 2009 10:08:54 +0200
From: Heinrich Apfelmus <apfel...@quantentunnel.de>
Subject: [Haskell-beginners] Re: uses of random number generators
To: beginners@haskell.org
Message-ID: <h4h2tv$b4...@ger.gmane.org>
Content-Type: text/plain; charset=ISO-8859-1

Michael P Mossey wrote:
> I have an application for random numbers. So far, in my journey with
> Haskell, I have learned basics and a few things about monads, and I was
> hoping I could get some guidance how to employ random # gens.
> 
> Can I get a few examples or pointers? I believe I will have to run this
> in a State monad or the IO monad, will I not?

Yes, the  State StdGen  monad for example. Note however that it's best
to keep it abstract, i.e. to hide the fact that it happens to be a state
monad.

See also

  http://lukepalmer.wordpress.com/2009/01/17/use-monadrandom/

for making the case,

  http://en.wikibooks.org/wiki/Haskell/Understanding_monads

for detailing the random number monad, and

  http://apfelmus.nfshost.com/random-permutations.html

for an example use.



Regards,
apfelmus

--
http://apfelmus.nfshost.com



------------------------------

Message: 5
Date: Fri, 24 Jul 2009 16:49:20 +0000 (GMT)
From: Daniel Everett <djeinb...@yahoo.co.uk>
Subject: [Haskell-beginners] Getting the Takusen example code to
        compile -       failed import problem
To: beginners@haskell.org
Message-ID: <182701.43131...@web23001.mail.ird.yahoo.com>
Content-Type: text/plain; charset=utf-8

I have Takusen 0.8.5 installed and I'm trying to build the code found at 
http://darcs.haskell.org/takusen/doc/html/Database-Enumerator.html using ghc 
6.10.3.  This always fails with the error:  

Could not find module `Database.Oracle.Enumerator'

The analogous errors are encountered if I substitute Oracle with Sqlite, 
Postgresql or ODBC.  Any ideas how to resolve this?

TIA,

Daniel


      



------------------------------

Message: 6
Date: Mon, 27 Jul 2009 00:47:12 -0400
From: Dean Herington <heringtonla...@mindspring.com>
Subject: Re: [Haskell-beginners] Question on monads and laziness
To: Lakshmi Narasimhan Vaikuntam <lakshminaras2...@gmail.com>,
        Beginners@haskell.org
Message-ID: <a06240800c6926cb99...@[192.168.1.100]>
Content-Type: text/plain; charset="us-ascii"

At 9:23 AM +0530 7/26/09, Lakshmi Narasimhan Vaikuntam wrote:
>Hello
>I am studying Real World Haskell chapter 9. Here is a snippet of code
>
>data Info = Info {
>       infoPath :: FilePath
>     , infoPerms :: Maybe Permissions
>
>     , infoSize :: Maybe Integer
>     , infoModTime :: Maybe ClockTime
>     } deriving (Eq, Ord, Show)
>
>getInfo :: FilePath -> IO Info
>-- file: ch09/ControlledVisit.hs
>
>traverse order path = do
>     names <- getUsefulContents path
>     contents <- mapM getInfo (path : map (path </>) names)
>     liftM concat $ forM (order contents) $ \info -> do
>       if isDirectory info && infoPath info /= path
>
>         then traverse order (infoPath info)
>         else return [info]
>
>getUsefulContents :: FilePath -> IO [String]
>getUsefulContents path = do
>     names <- getDirectoryContents path
>     return (filter (`notElem` [".", ".."]) names)
>
>
>isDirectory :: Info -> Bool
>isDirectory = maybe False searchable . infoPerms
>When I read about IO in the previous chapter, I learnt that reading 
>a file can be done lazily.
>Here my doubt is that whether the expression "order contents" would 
>generate a list of directory contents (held in memory) for use in 
>forM construct. Because in a subsequent para, I find this line.
>
>"If we are traversing a directory containing 100,000 files of which 
>we care about three, we'll allocate a 100,000-element list before we 
>have a chance to trim it down to the three we really want"
>
>
>Wouldn't laziness ensure that in the traverse function, when 
>iterating over directory contents using the list generated by "order 
>contents",
>it will generate just one element at a time and then free the memory 
>for that entry immediately since we are not using the referencing 
>list
>
>anymore in the rest of the function.
>
>Not sure whether I have understood the concept of laziness w.r.t 
>monads correctly. Please clarify my doubts with regard to the code 
>snippet.
>
>Thanks for your time.
>--
>Regards
>Lakshmi Narasimhan T V

These issues are a bit subtle.

Yes, a file can be read lazily.  What this means is that there are 
I/O actions (readFile and getContents, for example) which produce 
lazy strings, for which the underlying read operations are done as 
needed as the successive characters of the strings are demanded.  But 
this kind of "lazy I/O" is not at play here.

I/O is a special monad.  Its semantics are that I/O actions are 
performed in sequence, regardless of demands (or lack thereof) on the 
actions' results.  (This is so that real-world side effects occur in 
determinstic order.)  And the I/O actions themselves determine how 
much computation they do before offering their results.

In the code you cited, `traverse` calls `getUsefulContents` to 
generate a list of names.  `getUsefulContents` uses 
`getDirectoryContents`, which computes its result list completely 
before returning it.  (The documentation doesn't say that explicitly. 
It is implied because it doesn't say that the result is returned 
lazily.)  So both `names` and `contents` could be very large, as the 
authors note.

Some describe these semantics by saying "the I/O monad is strict", 
but I don't think that's a precise statement, because strictness is a 
property of a function (and its arguments), not of a monad (at least 
as far as I understand).

I hope this helps.

Dean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090727/4162c9d2/attachment-0001.html

------------------------------

Message: 7
Date: Tue, 28 Jul 2009 09:21:05 +0100
From: "Bayley, Alistair" <alistair.bay...@invesco.com>
Subject: RE: [Haskell-beginners] Getting the Takusen example code to
        compile -failed import problem
To: "Daniel Everett" <djeinb...@yahoo.co.uk>
Cc: beginners@haskell.org
Message-ID:
        <125eacd0cae4d24abdb4d148c4593da911026...@gblonxmb02.corp.amvescap.net>
        
Content-Type: text/plain; charset="us-ascii"

> From: beginners-boun...@haskell.org 
> [mailto:beginners-boun...@haskell.org] On Behalf Of Daniel Everett
> 
> I have Takusen 0.8.5 installed and I'm trying to build the 
> code found at 
> http://darcs.haskell.org/takusen/doc/html/Database-Enumerator.
html using ghc 6.10.3.  This always fails with the error:  
> 
> Could not find module `Database.Oracle.Enumerator'
> 
> The analogous errors are encountered if I substitute Oracle 
> with Sqlite, Postgresql or ODBC.  Any ideas how to resolve this?


Hello Daniel,

Could you please send me the output from "ghc-pkg describe Takusen" ? It
might be that the various backend modules have not been installed.

The output from the installation process might also be useful e.g. setup
-v configure

Alistair
*****************************************************************
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*****************************************************************



------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 13, Issue 17
*****************************************

Reply via email to