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: monad nomad gonad gomad (prad)
2. Re: Re: monad nomad gonad gomad (Michael Mossey)
3. Re: monad nomad gonad gomad (prad)
4. Re: Re: monad nomad gonad gomad (John Obbele)
5. Re: Re: monad nomad gonad gomad (Michael Mossey)
6. hClose: illegal operation (handle is finalized) and/or
<<loop>> (Travis Erdman)
7. Re: hClose: illegal operation (handle is finalized) and/or
<<loop>> (Felipe Lessa)
8. Re: hClose: illegal operation (handle is finalized) and/or
<<loop>> (anderson leo)
----------------------------------------------------------------------
Message: 1
Date: Tue, 17 Aug 2010 10:25:25 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] Re: monad nomad gonad gomad
To: [email protected]
Message-ID: <20100817102525.6ed22...@gom>
Content-Type: text/plain; charset=US-ASCII
On Sun, 15 Aug 2010 21:11:52 +0200
Ertugrul Soeylemez <[email protected]> wrote:
> Just remember this: You have an IO computation? You want to refer to
> its result? Fine, just use '<-'. That's it.
>
that's what i've been doing the past two days and it works ... except
in one case.
for example, i have:
========
flData <- readFile key
let (sec:tle:kwd:dsc:url:typ:dat:txt) = lines flData
========
so flData is the computation which reads the contents of a file and i
can take that and do a lines on it. no problem.
however, i also have:
========
subs (l:ls)
| ls==[] = l : []
| otherwise =
case l of
"```" -> do
let (code:z) = ls
str = gt code -- works
--str <- readFile "B" -- doesn't work
subs (str:z)
_ -> l : subs ls
gt s =
case s of
"B" -> "BBBB"
"C" -> "CCCC"
========
now str = gt code is fine because it's not monadic. however, if i try
to get the data from a file or a db, it gives the error
Couldn't match expected type `[[Char]]'
against inferred type `IO b'
because i'm trying to get an IO monad into a [String] from what i
understand.
so i'm trying different things here, but haven't found a way yet.
> In fact, I recommend not to think more, but to think less.
>
ok! i'll see what i can do!
as you rightly keep telling me, i'm being way too complicated. :D
i'm enjoying your extensive tutorial:
http://ertes.de/articles/monads.html
though it's going slowly, but things are coming together little by
little.
i was also pointed to this:
http://codingcactus.wordpress.com/2010/08/16/writemonad1/
and i just saw mike vanier's post here:
very detailed monad tutorials (a series of articles)
http://mvanier.livejournal.com/3917.html
so with all this help i'm sure to 'get it' eventually!
> At some point it will make click and suddenly everything gets clear.
> Everybody has this experience with monads (unless they give up).
>
no worries about that!
i do see the light in the long tunnel - now it's just a matter of
getting to it.
--
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: Tue, 17 Aug 2010 13:34:01 -0700
From: Michael Mossey <[email protected]>
Subject: Re: [Haskell-beginners] Re: monad nomad gonad gomad
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
prad wrote:
> On Sun, 15 Aug 2010 21:11:52 +0200
> however, i also have:
>
> ========
> subs (l:ls)
> | ls==[] = l : []
> | otherwise =
> case l of
> "```" -> do
> let (code:z) = ls
> str = gt code -- works
> --str <- readFile "B" -- doesn't work
> subs (str:z)
> _ -> l : subs ls
>
>
> gt s =
> case s of
> "B" -> "BBBB"
> "C" -> "CCCC"
> ========
Can I make a general suggestion? It looks to me like you need to work
through a book like "Real World Haskell" sequentially from the beginning.
It looks like you are trying to do complex things before you've mastered
simple things.
Mike
------------------------------
Message: 3
Date: Tue, 17 Aug 2010 13:59:44 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] Re: monad nomad gonad gomad
To: [email protected]
Message-ID: <20100817135944.4b016...@gom>
Content-Type: text/plain; charset=US-ASCII
On Tue, 17 Aug 2010 13:34:01 -0700
Michael Mossey <[email protected]> wrote:
> It looks to me like you need to work
> through a book like "Real World Haskell" sequentially from the
> beginning.
>
well i'm doing that too, michael. (i remember you made this
suggestion to me several weeks ago and i have worked my way
through a few chapters in rw and most of the haskell wiki
tutorial).
i've joined the reading group on the agora forum for
rwhaskell. i'm also going through the video lectures here:
http://www.cs.nott.ac.uk/~gmh/book.html
what i find interesting is that you say what i'm trying to do here is
complicated, because it seemed to me it was one of the simpler things
that i actually understood. now i think i'm in trouble, because
evidently i haven't understood it too well. :D
it seemed to me that in one situation i was trying to get data from a
function gt which just returns a string:
gt :: String -> String
in the other situation, i wanted to get the same data from a file, but
can't seem to because the file is returning an IO instead of a String
(in fact it is expecting [String]).
however, i know you are right. i really need to get a better
understanding of the basics, so i'll focus on that for the next few
days and see if i can understand these problems i'm having better than
i presently do.
--
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: 4
Date: Wed, 18 Aug 2010 00:26:21 +0200
From: John Obbele <[email protected]>
Subject: Re: [Haskell-beginners] Re: monad nomad gonad gomad
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Tue, Aug 17, 2010 at 01:59:44PM -0700, prad wrote:
> On Tue, 17 Aug 2010 13:34:01 -0700
> Michael Mossey <[email protected]> wrote:
>
> > It looks to me like you need to work
> > through a book like "Real World Haskell" sequentially from the
> > beginning.
> >
> well i'm doing that too, michael. (i remember you made this
> suggestion to me several weeks ago and i have worked my way
> through a few chapters in rw and most of the haskell wiki
> tutorial).
Well, I may not help you, Prad, but the enormous amount of
questions you've send to this mailing-list have helped me to
re-discover many basic concepts of Haskell ,-)
I am also trying to learn it since last January. So I can add
this piece of advice for you : do not rush things. It seems you
are reading too many different contents on monads lately. That's
strange for someone as lazy as me who cannot digest this much
amount of data in such a short time.
I usually evaluate my time spend on a specific subject as the
number of nights spend between each of my readings and I can say
this: monads have taken me a good month of sleep to figure them
out :)
> what i find interesting is that you say what i'm trying to do here is
> complicated, because it seemed to me it was one of the simpler things
> that i actually understood. now i think i'm in trouble, because
> evidently i haven't understood it too well. :D
No it's not simple. I am not able to read Haskell code which play
with database and files, so your code is already behind my
understanding.
> it seemed to me that in one situation i was trying to get data from a
> function gt which just returns a string:
> gt :: String -> String
>
> in the other situation, i wanted to get the same data from a file, but
> can't seem to because the file is returning an IO instead of a String
> (in fact it is expecting [String]).
>From what I remember, RWH's authors always advocate to
separate monadic code from basic code. You should pause for a
moment and refactor your code so you do not get caught in this
situation again (situation = trying to read a file as you read a
String).
If I were you, I would break my problem in even smaller chunks
and try to analyze patiently how Haskell could process each
individually.
regards,
/John
P.S.: ah ! and keep posting questions on precise problems you
encounter. I may be interested in them :p
------------------------------
Message: 5
Date: Tue, 17 Aug 2010 16:02:22 -0700
From: Michael Mossey <[email protected]>
Subject: Re: [Haskell-beginners] Re: monad nomad gonad gomad
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
prad wrote:
> On Tue, 17 Aug 2010 13:34:01 -0700
> Michael Mossey <[email protected]> wrote:
>
>> It looks to me like you need to work
>> through a book like "Real World Haskell" sequentially from the
>> beginning.
>>
> what i find interesting is that you say what i'm trying to do here is
> complicated, because it seemed to me it was one of the simpler things
> that i actually understood. now i think i'm in trouble, because
> evidently i haven't understood it too well. :D
It may be simple to do once you understand, but your past several questions
relate to
- purity
- do-notation as syntactic sugar for monadic computations
- the IO monad
If you understood these things you would not be running into this trouble,
or you would quickly see the problem yourself. Because most books and
tutorials introduce these things gradually, giving you lots of practice
problems /at the level they are introduced/, I think your learning process
would go more smoothly if you
- pick a single book. don't try to digest all these different tutorials and
books at once
- read it sequentially
- work the problems. if you want to branch into your own problem, stay
close to the examples you've seen so far
Best wishes,
Mike
------------------------------
Message: 6
Date: Tue, 17 Aug 2010 16:39:26 -0700 (PDT)
From: Travis Erdman <[email protected]>
Subject: [Haskell-beginners] hClose: illegal operation (handle is
finalized) and/or <<loop>>
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
> > putStrLn $ show result
> >
> > <<loop>>
>
> That is the *real* error message.
>
> It means that where you define result, you refer to result
> also on the right-hand side in a way that is an endless
> loop instead of well-behaved recursion.
>
> We would have to see more of your code to be able to
> say much more.
Thank you very much ... now I have isolated the offending "loop" code:
I am folding with a function that takes a tree and the input data, and delivers
a "processed"/"updated" tree. The function that is used in the fold is
"calcTree". calcTree is also recursive ... it updates the root node, then
recursively calls itself to update each of its children, which is all working
fine. Here are simplified versions of my structure:
data Tree a = Node a [Tree a]
calcTree (Node oldData oldsubtree) input = Node newData recurseChildren
where
{-calculate newData from oldData and input-}
recurseChildren = if {BOOLEANS} then oldsubtree else map (\old ->
calcTree old input) oldsubtree
And, in words: if certain conditions become true, there will be no change in
any decedent node from the current node (ie all newData = oldData, and tree
structure never changes), so rather than waste exponential time traversing all
the decedent nodes, I'd like to just re-use the ones I already have, as they
are identical. This is "pruning" the tree. If I remove this pruning, the
"<<LOOP>>" objection ceases and the code executes as expected ... except it
takes lots longer than it should, because there are usually lots of oppt'ys for
pruning, and I'd rather not explicitly traverse all of them.
How can I make this work?
Thanks again for all the A's to my Q's !
------------------------------
Message: 7
Date: Tue, 17 Aug 2010 20:57:24 -0300
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] hClose: illegal operation (handle is
finalized) and/or <<loop>>
To: Travis Erdman <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Tue, Aug 17, 2010 at 8:39 PM, Travis Erdman <[email protected]> wrote:
> calcTree (Node oldData oldsubtree) input = Node newData recurseChildren
> Â where
> Â Â Â {-calculate newData from oldData and input-}
> Â Â Â recurseChildren = if {BOOLEANS} then oldsubtree else map (\old ->
> calcTree old input) oldsubtree
>
> And, in words: Â if certain conditions become true, there will
> be no change in any decedent node from the current node (ie all
> newData = oldData, and tree structure never changes), so rather
> than waste exponential time traversing all the decedent nodes,
> I'd like to just re-use the ones I already have, as they are
> identical. Â This is "pruning" the tree. Â If I remove this
> pruning, the "<<LOOP>>" objection ceases and the code executes
> as expected ... except it takes lots longer than it should,
> because there are usually lots of oppt'ys for pruning, and I'd
> rather not explicitly traverse all of them.
>
> How can I make this work?
Perhaps in your {BOOLEANS} you are referring to
'recurseChildren', which in turn needs the {BOOLEANS}?
HTH!
--
Felipe.
------------------------------
Message: 8
Date: Wed, 18 Aug 2010 08:04:23 +0800
From: anderson leo <[email protected]>
Subject: Re: [Haskell-beginners] hClose: illegal operation (handle is
finalized) and/or <<loop>>
To: Travis Erdman <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
It seems there is no empty node which might make a inifinite loop.
--Andrew
On Wed, Aug 18, 2010 at 7:39 AM, Travis Erdman <[email protected]>wrote:
> > > putStrLn $ show result
> > >
> > > <<loop>>
> >
> > That is the *real* error message.
> >
> > It means that where you define result, you refer to result
> > also on the right-hand side in a way that is an endless
> > loop instead of well-behaved recursion.
> >
> > We would have to see more of your code to be able to
> > say much more.
>
> Thank you very much ... now I have isolated the offending "loop" code:
>
> I am folding with a function that takes a tree and the input data, and
> delivers a "processed"/"updated" tree. The function that is used in the
> fold is "calcTree". calcTree is also recursive ... it updates the root
> node, then recursively calls itself to update each of its children, which is
> all working fine. Here are simplified versions of my structure:
>
> data Tree a = Node a [Tree a]
>
> calcTree (Node oldData oldsubtree) input = Node newData recurseChildren
> where
> {-calculate newData from oldData and input-}
> recurseChildren = if {BOOLEANS} then oldsubtree else map (\old ->
> calcTree old input) oldsubtree
>
> And, in words: if certain conditions become true, there will be no change
> in any decedent node from the current node (ie all newData = oldData, and
> tree structure never changes), so rather than waste exponential time
> traversing all the decedent nodes, I'd like to just re-use the ones I
> already have, as they are identical. This is "pruning" the tree. If I
> remove this pruning, the "<<LOOP>>" objection ceases and the code executes
> as expected ... except it takes lots longer than it should, because there
> are usually lots of oppt'ys for pruning, and I'd rather not explicitly
> traverse all of them.
>
> How can I make this work?
>
> Thanks again for all the A's to my Q's !
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100817/c0a09771/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 26, Issue 36
*****************************************