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: gnuplot problem in ghci (Brandon S. Allbery KF8NH)
2. Re: gnuplot problem in ghci (Scott N. Walck)
3. Re: gnuplot problem in ghci (Brandon S. Allbery KF8NH)
4. Re: lazy IO in readFile (Andrew Sackville-West)
5. Re: lazy IO in readFile (Andrew Sackville-West)
6. Help with slow algorithm (Diego Echeverri)
7. Re: Help with slow algorithm (Brandon S. Allbery KF8NH)
8. Re: Help with slow algorithm (Diego Echeverri)
----------------------------------------------------------------------
Message: 1
Date: Fri, 14 May 2010 17:16:14 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] gnuplot problem in ghci
To: "Scott N. Walck" <[email protected]>
Cc: beginners beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On May 14, 2010, at 14:21 , Daniel Fischer wrote:
> On Friday 14 May 2010 19:48:20, Scott N. Walck wrote:
>> shown below, the keyboard no longer echos my input to
>> ghci. ghci will still do what I ask, as in computing 3+4
>> below, but I could not see the "3+4" until after I hit
>> return.
>>
>> This is gnuplot 0.3.4.
>> Could anyone suggest an idea?
>
> Sorry, no. Though it looks like a buffering problem.
To me it sounds like the terminal's been reset to line mode. Type
"tty" to the shell before starting ghci (it will output something
like /dev/pts/3 or /dev/ttys003 or /dev/ptyp3), then when the problem
happens switch to another terminal and type "stty -a </dev/pts/3 |
grep icanon" (substituting the output of the "tty" above). Look for
"icanon" or "-icanon"; the former is line mode, the latter is
character mode (ghci's readline requires the latter).
This won't help you solve it but at least gives you some information
to put in the bug report.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url :
http://www.haskell.org/pipermail/beginners/attachments/20100514/e3497efd/PGP-0001.bin
------------------------------
Message: 2
Date: Fri, 14 May 2010 19:16:37 -0400
From: "Scott N. Walck" <[email protected]>
Subject: Re: [Haskell-beginners] gnuplot problem in ghci
To: [email protected]
Message-ID: <20100514231637.ga13...@walck-nsf>
Content-Type: text/plain; charset=us-ascii
Brandon,
Yes, that looks like what is happening. Here are before and after
a graphics command.
$ stty -a </dev/pts/1 | grep icanon
isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
$ stty -a </dev/pts/1 | grep icanon
isig icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
Thanks,
Scott
On Fri, May 14, 2010 at 05:16:14PM -0400, Brandon S. Allbery KF8NH wrote:
> On May 14, 2010, at 14:21 , Daniel Fischer wrote:
> >On Friday 14 May 2010 19:48:20, Scott N. Walck wrote:
> >>shown below, the keyboard no longer echos my input to
> >>ghci. ghci will still do what I ask, as in computing 3+4
> >>below, but I could not see the "3+4" until after I hit
> >>return.
> >>
> >>This is gnuplot 0.3.4.
> >>Could anyone suggest an idea?
> >
> >Sorry, no. Though it looks like a buffering problem.
>
>
> To me it sounds like the terminal's been reset to line mode. Type
> "tty" to the shell before starting ghci (it will output something
> like /dev/pts/3 or /dev/ttys003 or /dev/ptyp3), then when the
> problem happens switch to another terminal and type "stty -a
> </dev/pts/3 | grep icanon" (substituting the output of the "tty"
> above). Look for "icanon" or "-icanon"; the former is line mode,
> the latter is character mode (ghci's readline requires the latter).
>
> This won't help you solve it but at least gives you some information
> to put in the bug report.
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
> system administrator [openafs,heimdal,too many hats] [email protected]
> electrical and computer engineering, carnegie mellon university KF8NH
>
>
--
Scott N. Walck
Associate Professor of Physics
Lebanon Valley College
Annville, PA 17003
phone: 717-867-6153
fax: 717-867-6075
email: [email protected]
------------------------------
Message: 3
Date: Fri, 14 May 2010 19:39:18 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] gnuplot problem in ghci
To: "Scott N. Walck" <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On May 14, 2010, at 19:16 , Scott N. Walck wrote:
> Yes, that looks like what is happening. Here are before and after
> a graphics command.
So a workaround would be that after running a graphics command, run
stty -icanon </dev/pts/1
(yes, you want "<" not ">") to fix the terminal settings. Not much of
a handy workaround, sadly.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url :
http://www.haskell.org/pipermail/beginners/attachments/20100514/65af70e9/PGP-0001.bin
------------------------------
Message: 4
Date: Fri, 14 May 2010 16:51:17 -0700
From: Andrew Sackville-West <[email protected]>
Subject: Re: [Haskell-beginners] lazy IO in readFile
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Sorry, I got distracted for a couple of days.
On Sat, May 08, 2010 at 02:16:27PM +0200, Daniel Fischer wrote:
> On Saturday 08 May 2010 04:47:14, Andrew Sackville-West wrote:
> >
> > Please ignore, for the moment, whatever *other* problems (idiomatic or
> > just idiotic) that may exist above and focus on the IO problem.
> >
>
> Sorry, can't entirely. Unless the number of rss items remains low, don't
> use lists, use a Set.
I knew people wouldn't be able to entirely, but I was trying to focus
on just one problem for the moment. THanks for the tip on Set. I don't
anticipate it really being a need, but it's a good idea. Ideally, I'd
like to come up with something more robust than just matching on
titles as well, but it works for the moment.
>
> > This code works fine *if* the file "testfile" has in it some subset of
> > the testData list. If it has the complete set, it fails with a "resource
> > busy" exception.
> >
> > Okay, I can more or less understand what's going on here. Each letter
> > in the testData list gets compared to the contents of the file, but
> > because they are *all* found, the readFile call never has to try and
> > fail to read the last line of the file. Thus the file handle is kept
> > open lazily waiting around not having reached EOF. Fair enough.
> >
> > But what is the best solution? One obvious one, and the one I'm using
> > now, is to move the appendFile call into a function with guards to
> > prevent trying to append an empty list to the end of the file. This
> > solves the problem not by forcing the read on EOF, but by not
> > bothering to open the file for appending:
> >
> > writeHistory [] = return ()
> > writeHistory ni = appendFile "testfile" . unlines $ ni
> >
> > And this makes some sense. It's silly to try to write nothing to a
> > file.
>
> Yes. In any case,
>
> unless (null newItems) $ appendFile "testfile" $ unlines newItems
>
> seems cleaner.
indeed. Thanks.
>
> >
> > But it also rubs me the wrong way. It's not solving the problem
> > directly -- closing that file handle. So there's my question, how can
> > I close that thing? Is there some way to force it?
>
> For almost all practical purposes, there is (despite the fact that what
> Stephen said is basically right, although a little overstated in my
> opinion).
> You have to force the entire file to be read, the standard idiom is using
>
> x `seq` doSomethingElse
>
> where x is a value that requires the entire file to be read, in your case
> x = length currItems is a natural choice.
d'oh.
> That way, you effectively have made readFile strict without sacrificing too
> much niceness of the code (withFile and hGetLine mostly are much uglier
> IMO).
I know I"m probably not really thinking about it in the right way, but
withFile and hGetLine don't seem to be a good fit because of the
current structure. I'm using the existing data in the file as a filter
to determine what new data to put in the file. like this:
items <- oldTitles `seq` liftM (filterItems oldTitles) $ buildItems srcs
where builtItems::[String] -> IO [Item], and filterItems::[String] ->
[Item] -> [Item] (I suppose I should post the whole file. You can see
it here: http://git.swclan.homelinux.org/rss2email.git)
Anyway, filterItems is doing 'filter (isNew oldItems) items',
effectively, and putting that into a withFile do structure seems not
right.
Thanks for the help
A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url :
http://www.haskell.org/pipermail/beginners/attachments/20100514/e14b54d6/attachment-0001.bin
------------------------------
Message: 5
Date: Fri, 14 May 2010 16:57:23 -0700
From: Andrew Sackville-West <[email protected]>
Subject: Re: [Haskell-beginners] lazy IO in readFile
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
sorry, I was distracted for a few days.
On Sat, May 08, 2010 at 11:38:25PM +1200, Stephen Blackheath [to
Haskell-Beginners] wrote
[...]
>
> In the case of 'readFile', this becomes, "Can I assume that for the life
> of the program, the file's contents will never change?" (Haskell abides
> in a Zen-like 'eternal now'.) For a program that reads a config file
> once on startup, the answer might be "yes", and cheating may not
> introduce any risks.
In fact, I know the file will change over the life of the program
because I'm appending to it. Though in theory, I only need to read it
all in once and then after some filtering and other operations, append
to it.
>
> Perhaps I can give you some more insight by saying this: Laziness adds
> complexity to the reasoning necessary to understand how your program
> will execute.
yes. I'm with you there.
> Purity means that this complexity is neutralized and
> becomes the compiler's problem, not yours. You have to remember that
> while the tiniest little piece of information calculated from the
> contents of your 'readFile' remains unevaluated, the file will not
> close. That's very difficult to reason about.
indeed.
>
> Another thing to consider is, if the code you're implementing relies on
> lazy I/O, might you want to use it in a big program? If so, surely it
> would be better to do it in a more general way to begin with. One of
> the things monads are especially good for is replacing lazy I/O.
>
> You might object, "Lazy I/O is so incredibly brilliant, but you are
> telling me I can't use it! That really ruins Haskell for me if one of
> its most amazing features is not allowed!"
>
> I know this seems very unfair. But my reply is, "Purity really is
> *that* good. It's even worth giving up lazy I/O for - that's how good it
> is."
I really agree with you, to the extent my limited knowledge and
understanding allow, and so am willing to try to learn this...
>
> >> I'd recommend using withFile and hGetLine, like this:
> >>
> >> withFile "testfile" ReadMode $ \h -> do
> >> ...
> >> l <- hGetLine h
I'm having trouble determining how to put this into the existing
context of a string of filter's and maps where the contents of the
file are used in a predicate to a filter. (if you really want you can
look at my ridiculous code at
http://git.swclan.homelinux.org/rss2email.git)
I suppose that means I need to rethink the structure of my program
(which already seems to be necessary anyway...).
[...]
> A parting thought: One of the great things about Haskell (compared with
> imperative programming) is that there are dozens of things you don't
> have to reason about any more, so you can concentrate on solving your
> problem. Do you see what I'm saying? Why even bother reasoning about
> whether laziness can get you? Just make everything pure and you don't
> have to. *
>
> (* I don't want to mislead you and make you think Haskell is something
> it's not. Therefore I need to add here that you *do* need to reason
> about the *space and CPU usage* of your code in the presence of
> laziness. IMO this is the only serious cost of using Haskell - the rest
> is benefit.)
thanks for your thoughtful comments.
A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url :
http://www.haskell.org/pipermail/beginners/attachments/20100514/ffa76ce7/attachment-0001.bin
------------------------------
Message: 6
Date: Fri, 14 May 2010 20:13:24 -0500
From: Diego Echeverri <[email protected]>
Subject: [Haskell-beginners] Help with slow algorithm
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi guys.
I've been playing with https://www.spoj.pl/ to get better with Haskell.
I'm trying to do: https://www.spoj.pl/problems/PALIN/
Basically given a number k, you have to find a number bigger than k
that is palindrome. The thing is that k can be 1000000 digits long.
I have learnt a bunch of things doing this exercise but I'm still
getting time-limit exception.
Here's the code: http://gist.github.com/401880
I believe that the bottleneck is in the addOne function (Specially in
the case where you have a bunch of nines). I have rewritten it to use
STArray but isn't fast enough.
doing: addOne $ B.replicate 500000 'a' takes too much time!
Can anybody point me out of better (faster) ways to improve the code?
I don't need my code fixed, just suggestions and clues about things to
try.
Thanks!
Diego Echeverri
------------------------------
Message: 7
Date: Fri, 14 May 2010 21:23:50 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] Help with slow algorithm
To: Diego Echeverri <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On May 14, 2010, at 21:13 , Diego Echeverri wrote:
> I have learnt a bunch of things doing this exercise but I'm still
> getting time-limit exception.
>
> Here's the code: http://gist.github.com/401880
>
> I believe that the bottleneck is in the addOne function (Specially in
> the case where you have a bunch of nines). I have rewritten it to use
> STArray but isn't fast enough.
> doing: addOne $ B.replicate 500000 'a' takes too much time!
http://www.haskell.org/haskellwiki/Performance/GHC is the place to
start.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url :
http://www.haskell.org/pipermail/beginners/attachments/20100514/ba6a8eab/PGP-0001.bin
------------------------------
Message: 8
Date: Fri, 14 May 2010 20:41:06 -0500
From: Diego Echeverri <[email protected]>
Subject: Re: [Haskell-beginners] Help with slow algorithm
To: "Brandon S. Allbery KF8NH" <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Thanks Brandon.
BTW... I just noticed I "Fucked up" the last gist.
http://gist.github.com/401924
On Fri, May 14, 2010 at 8:23 PM, Brandon S. Allbery KF8NH
<[email protected]> wrote:
> On May 14, 2010, at 21:13 , Diego Echeverri wrote:
>>
>> I have learnt a bunch of things doing this exercise but I'm still
>> getting time-limit exception.
>>
>> Here's the code: http://gist.github.com/401880
>>
>> I believe that the bottleneck is in the addOne function (Specially in
>> the case where you have a bunch of nines). I have rewritten it to use
>> STArray but isn't fast enough.
>> doing: addOne $ B.replicate 500000 'a' takes too much time!
>
> http://www.haskell.org/haskellwiki/Performance/GHC is the place to start.
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
> system administrator [openafs,heimdal,too many hats] [email protected]
> electrical and computer engineering, carnegie mellon university KF8NH
>
>
>
--
Att: Diego Echeverri Saldarriaga
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 23, Issue 20
*****************************************