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: proper way to read fold types (prad)
2. "module Main" from hitchhikers guide cd fit example
([email protected])
3. Re: "module Main" from hitchhikers guide cd fit example
(Johann Bach)
4. Re: "module Main" from hitchhikers guide cd fit example
([email protected])
5. Re: "module Main" from hitchhikers guide cd fit example
(Brent Yorgey)
6. MonadPlus (Johann Bach)
7. Re: MonadPlus (Brent Yorgey)
8. Re: "module Main" from hitchhikers guide cd fit example
(Daniel Fischer)
9. State Monad for neurons? (Amy de Buitl?ir)
----------------------------------------------------------------------
Message: 1
Date: Tue, 27 Jul 2010 21:12:10 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] Re: proper way to read fold types
To: [email protected]
Message-ID: <20100727211210.6129c...@gom>
Content-Type: text/plain; charset=US-ASCII
On Mon, 26 Jul 2010 09:30:41 +0200
Ertugrul Soeylemez <[email protected]> wrote:
> Trying to interpret combinators (or even to find metaphors, as many
> people do) is not always the right thing to do.
>
ok this is what i wanted to know.
too much thinking not enough understanding.
i will change my ways.
thx to dan and brandon too.
--
In friendship,
prad
... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's
------------------------------
Message: 2
Date: Wed, 28 Jul 2010 03:42:19 -0500
From: [email protected]
Subject: [Haskell-beginners] "module Main" from hitchhikers guide cd
fit example
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
I'm trying to work my way through the hitchhikers guide, knowing nothing
about Haskell (my day-to-day programming is in Python with a sprinkling of
C). I've installed a binary distribution of Haskell Platform on my Mac.
GHCi reports version 6.12.3. I'm currently in "3 Chapter 2: Parsing the
input". I'm stuck on the module Main definition. In hello.hs it works as
expected:
module Main where
main = putStrLn "Hello world!"
but in my nascent cd fitting code I get a parse error at the token "module"
("parse error on input `module'"):
import Text.ParserCombinators.Parsec
-- parseInput parses output of "du -sb", which consists of many lines,
-- each of which describes single directory
parseInput =
do dirs <- many dirAndSize
eof
return dirs
-- Datatype Dir holds information about single directory - its size and name
data Dir = Dir Int String deriving Show
-- `dirAndSize` parses information about single directory, which is:
-- a size in bytes (number), some spaces, then directory name, which
extends till newline
dirAndSize =
do size <- many1 digit
spaces
dir_name <- anyChar `manyTill` newline
return (Dir (read size) dir_name)
module Main where
main =
do input <- getContents
putStrLn ("DEBUG: got input " ++ input)
When I comment out from "module Main where" to the end of the file
runhaskell complains "Not in scope: `main'", suggesting that the parse of
the code above it succeeded. When I comment out all the code above "module
Main where" and run it, it displays what's on stdin. It would appear there
is some sort of problem with the dirAndSize definition above that, but if
that was the case why didn't I get a parse error when removing the
definition of Main, unexpected EOF or something similar?
Note that at this point this is pretty much just a copy-and-paste exercise.
Perhaps there is some problem with copying indented
Any help appreciated,
--
Skip Montanaro - [email protected] - http://www.smontanaro.net/
------------------------------
Message: 3
Date: Wed, 28 Jul 2010 01:55:25 -0700
From: Johann Bach <[email protected]>
Subject: Re: [Haskell-beginners] "module Main" from hitchhikers guide
cd fit example
To: [email protected]
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Wed, Jul 28, 2010 at 1:42 AM, <[email protected]> wrote:
> I'm trying to work my way through the hitchhikers guide, knowing nothing
> about Haskell (my day-to-day programming is in Python with a sprinkling of
> C). I've installed a binary distribution of Haskell Platform on my Mac.
> GHCi reports version 6.12.3. I'm currently in "3 Chapter 2: Parsing the
> input". I'm stuck on the module Main definition. In hello.hs it works as
> expected:
>
The "module Main were" has to be the first line in the file.
------------------------------
Message: 4
Date: Wed, 28 Jul 2010 04:06:02 -0500
From: [email protected]
Subject: Re: [Haskell-beginners] "module Main" from hitchhikers guide
cd fit example
To: Johann Bach <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Johann> The "module Main were" has to be the first line in the file.
Thanks for the quick reply. That suggests a bugfix is needed in the
hitchhikers guide. In "Parsing the input" the first block of code contains
an import state, definition of parseInput, declaration of data and
definition of dirAndSize. Right after that it states:
Just add those lines to the top of "cd-fit.hs".
which is exactly what I did... I realize it's a wiki, so in theory I could
edit the text, but at this stage of the game you probably don't want me
crashing around there.
Skip
------------------------------
Message: 5
Date: Wed, 28 Jul 2010 10:10:02 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] "module Main" from hitchhikers guide
cd fit example
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Jul 28, 2010 at 04:06:02AM -0500, [email protected] wrote:
>
> Johann> The "module Main were" has to be the first line in the file.
>
> Thanks for the quick reply. That suggests a bugfix is needed in the
> hitchhikers guide. In "Parsing the input" the first block of code contains
> an import state, definition of parseInput, declaration of data and
> definition of dirAndSize. Right after that it states:
>
> Just add those lines to the top of "cd-fit.hs".
>
> which is exactly what I did... I realize it's a wiki, so in theory I could
> edit the text, but at this stage of the game you probably don't want me
> crashing around there.
Not at all, please edit it to something you would have found clear. I
suppose it ought to say something like "at the top of the file, right after
the module declaration" or something along those lines.
-Brent
------------------------------
Message: 6
Date: Wed, 28 Jul 2010 03:03:01 -0700
From: Johann Bach <[email protected]>
Subject: [Haskell-beginners] MonadPlus
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I'm looking at Douglas Auclair's MonadPlus article, here
http://www.haskell.org/sitewiki/images/6/6a/TMR-Issue11.pdf
So consider an example like
t2 = do
x <- [1,2,3]
y <- [1,2]
guard $ x+y > 2
return (x,y)
This uses the list instance of MonadPlus.
Now, Douglas is talking about his own code, not the above example, but
his own code is similar. And he says "the entire computation is
chained by mplus". I'm confused because I thought it was chained by
>>=. In fact, I can't see where the above code makes use of mplus. The
definition of "guard" uses mzero.
------------------------------
Message: 7
Date: Wed, 28 Jul 2010 11:51:07 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] MonadPlus
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Jul 28, 2010 at 03:03:01AM -0700, Johann Bach wrote:
> I'm looking at Douglas Auclair's MonadPlus article, here
> http://www.haskell.org/sitewiki/images/6/6a/TMR-Issue11.pdf
>
> So consider an example like
>
> t2 = do
> x <- [1,2,3]
> y <- [1,2]
> guard $ x+y > 2
> return (x,y)
>
> This uses the list instance of MonadPlus.
>
> Now, Douglas is talking about his own code, not the above example, but
> his own code is similar. And he says "the entire computation is
> chained by mplus". I'm confused because I thought it was chained by
> >>=. In fact, I can't see where the above code makes use of mplus. The
> definition of "guard" uses mzero.
You are correct. That sentence is an error. Indeed, it ought to say
"since the entire computation is chained with (>>=), a failure of one
test voids the entire branch". This is because of the required law
mzero >>= f = mzero
Chaining a bunch of computations with `mplus` would cause each to be
tried in turn until one succeeds, quite different than what Doug is
talking about in that sentence.
-Brent
------------------------------
Message: 8
Date: Wed, 28 Jul 2010 15:35:36 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] "module Main" from hitchhikers guide
cd fit example
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Wednesday 28 July 2010 10:55:25, Johann Bach wrote:
> On Wed, Jul 28, 2010 at 1:42 AM, <[email protected]> wrote:
> > I'm trying to work my way through the hitchhikers guide, knowing
> > nothing about Haskell (my day-to-day programming is in Python with a
> > sprinkling of C). I've installed a binary distribution of Haskell
> > Platform on my Mac. GHCi reports version 6.12.3. I'm currently in "3
> > Chapter 2: Parsing the input". I'm stuck on the module Main
> > definition. In hello.hs it works as expected:
>
> The "module Main were" has to be the first line in the file.
The first *code* line.
Pragmas, comments and whitespace can preceed it.
Generally, a module starts with
-- LANGUAGE pragmas
-- OPTIONS_TOOL pragmas
-- Module comment
-- Module Header
-- Imports
then come the definitions you make.
Pragmas and imports appear of course only if needed.
The module comment for haddocks is optional, but if you distribute a
library, it's good practice to have one.
The module header,
module Foo (exportlist) where
, is optional, if you omit it, "module Main (main) where" is assumed.
If you omit the export list ("module Foo where"), all top-level bindings
are exported.
------------------------------
Message: 9
Date: Wed, 28 Jul 2010 17:41:11 +0100
From: Amy de Buitl?ir <[email protected]>
Subject: [Haskell-beginners] State Monad for neurons?
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I'm implementing a cyclic neural network. At time t, each neuron will update
its output based on the outputs (at time t-1) of the neurons that it's
connected to. It will also update the weights for its connections according
to some learning rule, and it may destroy a connection or create a new one.
So far, the best way I can think of to do this is to have a master list of
neurons, and each neuron would know the indices for the other neurons it
connects to. I'd write a function to update the neuron (actually returning a
"new" neuron), and then do a "map" over the list with that function.
That seems OK, but I wonder if there's a better way. I suspect the State
monad could be used for this, but I can't figure out how to put the pieces
of the puzzle together. Here's what I was thinking:
- A connection could be a State monad, where the state is the source neuron
and the current weight, and the result would be the weighted input.
- A neuron could also be a State Monad, where the state is a list of
connections, and the result is the neuron's output.
I've read dozens of monad tutorials, but I can't figure out how to trigger
all the neurons to update themselves. Is the State Monad appropriate for
this problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100728/bc49a39a/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 25, Issue 54
*****************************************