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: indentation (Jorden Mauro)
2. Re: indentation (Magnus Therning)
3. indentation (Gabi)
4. Re: indentation (Magnus Therning)
5. RE: indentation (Luca Ciciriello)
6. space leak (Uchida Yasuo)
7. Re: space leak (Daniel Fischer)
8. Re: Re: [Haskell-beginners] space leak (Uchida Yasuo)
9. Re: space leak (Felipe Lessa)
----------------------------------------------------------------------
Message: 1
Date: Sun, 14 Feb 2010 21:57:05 -0500
From: Jorden Mauro <[email protected]>
Subject: Re: [Haskell-beginners] indentation
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Sun, Feb 14, 2010 at 8:51 PM, Brent Yorgey <[email protected]> wrote:
> On Sun, Feb 14, 2010 at 04:30:27PM -0500, Jorden Mauro wrote:
>> On Sun, Feb 14, 2010 at 3:20 PM, Daniel Fischer
>> <[email protected]> wrote:
>> > Am Sonntag 14 Februar 2010 20:54:54 schrieb John Moore:
>> >> Hi all,
>> >> I must be doing something wrong with my tabs. Because this
>> >> keeps telling me parse error. Can some one see if it is indentation. I'm
>> >> sending a file so as you'll be able to see what going on. If I copy it
>> >> here it can appear wrong the difference is with the Var expression.
>> >>
>> >> John
>> >
>> > First of all, *don't mix tabs and spaces for indentation* (best, don't use
>> > tabs at all).
>>
>> I find the latter a bit too restrictive, especially since I use a text
>> editor that is a glorified version of ed. Hitting the spacebar 19
>> times is too much to ask of me.
>>
>> And as such, I am occasionally forced to do something when a tab
>> doesn't get me past the word `where' or `let', but isn't that the
>> majority of what Layout specifies?
>>
>> Is there a good answer for caveman programmers who like ed and tabs?
>
> Another good answer is to use explicit curly braces and semicolons so
> you don't have to rely on layout.
Yes, I am a recovering C programmer. You caught me!
I really do appreciate the features of sam, and its simplicity is why
I like layout. Omit needless punctuation, I say.
>
> -Brent
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 2
Date: Mon, 15 Feb 2010 10:30:57 +0000
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] indentation
To: Jorden Mauro <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Sun, Feb 14, 2010 at 23:44, Jorden Mauro <[email protected]> wrote:
> On Feb 14, 2010, at 6:00 PM, Magnus Therning <[email protected]> wrote:
>> Are you sure you can't get it to also convert tabs to spaces?
>
> Not without reprogramming it. Of course, I could convert files by hand, but
> I could just as easily use spaces. I just thought tabs were acceptable.
>
> I was a contientious objector in the Tabs or Spaces War. Is just using
> spaces the Haskell Caveman Solution?
I'd argue the solution is to just use one. The issue is with mixing them!
/M
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org
http://therning.org/magnus identi.ca|twitter: magthe
------------------------------
Message: 3
Date: Mon, 15 Feb 2010 13:33:35 +0200
From: Gabi <[email protected]>
Subject: [Haskell-beginners] indentation
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
BTW, is there some indent tool for Haskell.
Something like "indent" command line tool for c?
--
Regards,
Gabi
http://bugspy.net
------------------------------
Message: 4
Date: Mon, 15 Feb 2010 12:08:06 +0000
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] indentation
To: Gabi <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Mon, Feb 15, 2010 at 11:33, Gabi <[email protected]> wrote:
> BTW, is there some indent tool for Haskell.
> Something like "indent" command line tool for c?
Since indentation is significant (in most source files) I suspect it
would be difficult to create an "indent"-like tool for Haskell.
If you want modify indentation, e.g. switch from tabs to spaces, or
change from 4 to 2 spaces then you can use any tool that lets you do a
search and replace.
/M
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org
http://therning.org/magnus identi.ca|twitter: magthe
------------------------------
Message: 5
Date: Mon, 15 Feb 2010 12:50:19 +0000
From: Luca Ciciriello <[email protected]>
Subject: RE: [Haskell-beginners] indentation
To: <[email protected]>, <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On MacOS X I use Emacs (Aqua). This version of emacs supports the indentation
utilities for Haskell.
Anyway you can downloads this tool for any GNU emacs here:
http://projects.haskell.org/haskellmode-emacs/
Bye.
Luca.
> Date: Mon, 15 Feb 2010 13:33:35 +0200
> From: [email protected]
> To: [email protected]
> Subject: [Haskell-beginners] indentation
>
> BTW, is there some indent tool for Haskell.
> Something like "indent" command line tool for c?
>
> --
> Regards,
> Gabi
>
> http://bugspy.net
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
_________________________________________________________________
Tell us your greatest, weirdest and funniest Hotmail stories
http://clk.atdmt.com/UKM/go/195013117/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100215/3bb1710b/attachment-0001.html
------------------------------
Message: 6
Date: Tue, 16 Feb 2010 00:44:51 +0900 (JST)
From: Uchida Yasuo <[email protected]>
Subject: [Haskell-beginners] space leak
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ascii
Hello,
I came across the following space leak problem today.
How can I fix this?
(Tested on Mac OS X 10.5.8, GHC 6.10.3)
-- test.hs
module Main where
import System
import qualified Data.ByteString.Lazy.Char8 as L
main = do args <- getArgs
let n = read $ args !! 0
cs <- L.getContents
let !a = L.take n cs
mapM_ (print . L.length) $ L.lines cs
print a
-- gen.hs
module Main where
main = do putStrLn $ take 1000000 $ cycle "foo"
main
These are compiled with the following options:
$ ghc --make -O2 test
$ ghc --make -O2 gen
The memory usage seems to depend on the argument(=17000) passed.
On my MacBook(Core2 Duo 2.0GHz), 16000 works fine.
$ ./gen | head -1000 | ./test 17000 +RTS -sstderr
...
3,793,673,564 bytes allocated in the heap
9,901,516 bytes copied during GC
635,576,092 bytes maximum residency (11 sample(s))
248,725,136 bytes maximum slop
1759 MB total memory in use (562 MB lost due to fragmentation)
Generation 0: 6941 collections, 0 parallel, 16.91s, 18.15s elapsed
Generation 1: 11 collections, 0 parallel, 0.03s, 0.03s elapsed
INIT time 0.00s ( 0.00s elapsed)
MUT time 3.04s ( 27.64s elapsed)
GC time 16.94s ( 18.18s elapsed)
EXIT time 0.00s ( 0.01s elapsed)
Total time 19.99s ( 45.82s elapsed)
%GC time 84.8% (39.7% elapsed)
Alloc rate 1,245,766,300 bytes per MUT second
Productivity 15.2% of total user, 6.6% of total elapsed
$ ./gen | head -1000 | ./test 16000 +RTS -sstderr
...
4,000,652,128 bytes allocated in the heap
7,428,180 bytes copied during GC
1,057,588 bytes maximum residency (1001 sample(s))
525,092 bytes maximum slop
5 MB total memory in use (1 MB lost due to fragmentation)
Generation 0: 6362 collections, 0 parallel, 0.10s, 0.12s elapsed
Generation 1: 1001 collections, 0 parallel, 0.09s, 0.09s elapsed
INIT time 0.00s ( 0.00s elapsed)
MUT time 2.59s ( 23.26s elapsed)
GC time 0.18s ( 0.22s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 2.77s ( 23.47s elapsed)
%GC time 6.6% (0.9% elapsed)
Alloc rate 1,545,246,968 bytes per MUT second
Productivity 93.4% of total user, 11.0% of total elapsed
--
Regards,
Yasuo Uchida
------------------------------
Message: 7
Date: Mon, 15 Feb 2010 18:07:16 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] space leak
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag 15 Februar 2010 16:44:51 schrieb Uchida Yasuo:
> Hello,
>
> I came across the following space leak problem today.
> How can I fix this?
> (Tested on Mac OS X 10.5.8, GHC 6.10.3)
>
> -- test.hs
> module Main where
>
> import System
> import qualified Data.ByteString.Lazy.Char8 as L
>
> main = do args <- getArgs
> let n = read $ args !! 0
> cs <- L.getContents
> let !a = L.take n cs
The problem is this. The Bang pattern does less than you probably think.
The definition of lazy ByteStrings is
data ByteString = Empty | Chunk {-# UNPACK #-} !S.ByteString ByteString
, so when you write
let !a = L.take n cs
, you force the constructor (null cs ? Empty : Chunk start rest), Since cs
is not empty, it's Chunk, and that forces the first part of the ByteString,
which will be as long as the prefix which stdin immediately delivers, but
at most the default chunk size (32K or 64K, normally [minus two words for
bookkeeping]).
If n is larger than a) the default chunk size or b) what L.getContents got
immediately[*], a holds on to the (almost) entire input and you have a bad
memory leak.
Fix: force a to be completely evaluated, e.g.
let !a = L.take n cs
!l = L.length a
By evaluating the length, a doesn't keep references to cs and all can be
garbage collected.
[*] how long the first chunk is, depends in this pipeline on scheduling,
number of available cores/CPUs, OS buffer size.
> mapM_ (print . L.length) $ L.lines cs
> print a
>
>
> -- gen.hs
> module Main where
>
> main = do putStrLn $ take 1000000 $ cycle "foo"
> main
>
>
> These are compiled with the following options:
>
> $ ghc --make -O2 test
> $ ghc --make -O2 gen
>
> The memory usage seems to depend on the argument(=17000) passed.
> On my MacBook(Core2 Duo 2.0GHz), 16000 works fine.
------------------------------
Message: 8
Date: Tue, 16 Feb 2010 03:02:13 +0900 (JST)
From: Uchida Yasuo <[email protected]>
Subject: Re: Re: [Haskell-beginners] space leak
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ascii
Oh, What a relief! Thank you for your clear explanation!
--- Daniel Fischer wrote:
> Am Montag 15 Februar 2010 16:44:51 schrieb Uchida Yasuo:
> > Hello,
> >
> > I came across the following space leak problem today.
> > How can I fix this?
> > (Tested on Mac OS X 10.5.8, GHC 6.10.3)
> >
> > -- test.hs
> > module Main where
> >
> > import System
> > import qualified Data.ByteString.Lazy.Char8 as L
> >
> > main = do args <- getArgs
> > let n = read $ args !! 0
> > cs <- L.getContents
> > let !a = L.take n cs
>
> The problem is this. The Bang pattern does less than you probably think.
> The definition of lazy ByteStrings is
>
> data ByteString = Empty | Chunk {-# UNPACK #-} !S.ByteString ByteString
>
> , so when you write
>
> let !a = L.take n cs
>
> , you force the constructor (null cs ? Empty : Chunk start rest), Since cs
> is not empty, it's Chunk, and that forces the first part of the ByteString,
> which will be as long as the prefix which stdin immediately delivers, but
> at most the default chunk size (32K or 64K, normally [minus two words for
> bookkeeping]).
>
> If n is larger than a) the default chunk size or b) what L.getContents got
> immediately[*], a holds on to the (almost) entire input and you have a bad
> memory leak.
>
> Fix: force a to be completely evaluated, e.g.
>
> let !a = L.take n cs
> !l = L.length a
>
> By evaluating the length, a doesn't keep references to cs and all can be
> garbage collected.
>
> [*] how long the first chunk is, depends in this pipeline on scheduling,
> number of available cores/CPUs, OS buffer size.
__
Regards,
Yasuo Uchida
------------------------------
Message: 9
Date: Mon, 15 Feb 2010 16:24:38 -0200
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] space leak
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Tue, Feb 16, 2010 at 12:44:51AM +0900, Uchida Yasuo wrote:
> The memory usage seems to depend on the argument(=17000) passed.
> On my MacBook(Core2 Duo 2.0GHz), 16000 works fine.
The default chunk size for bytestring-0.9.1.5 is 32k [1]. I
don't know why 16k is the magical number here. However, you
strictly compute take. When the number of bytes you take is
available in the first chunk, everything is done. If you need
more then one chunk, then that bang patter ! will force only the
*first* chunk, the others will be take'en lazily.
You can try to verify this by using L.toChunks and noting how
many chunks are being created.
[1]
http://hackage.haskell.org/packages/archive/bytestring/0.9.1.5/doc/html/src/Data-ByteString-Lazy-Internal.html#defaultChunkSize
HTH,
--
Felipe.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 20, Issue 26
*****************************************