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: Inconsistencies in type inference (David Virebayre)
2. what to do about excess memory usage (James Jones)
3. Re: Inconsistencies in type inference (Martin Ruderer)
4. Re: Inconsistencies in type inference (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Wed, 26 Jun 2013 13:01:45 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Inconsistencies in type inference
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAM_wFVuFXgwR2Mee_He=EpgDjdy8DvMJSViwwYR2=9yqdj8...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
2013/6/26 Frerich Raabe <[email protected]>:
> Are there other extensions which people would consider to be "generally good
> to have, unless you know a good reason *not* to enable them"?
I don't use the "crazy" stuff, but I find myself using often :
- NoMonomorphismRestriction
- OverloadedStrings
- BangPatterns
- GeneralizedNewtypeDeriving
David.
------------------------------
Message: 2
Date: Wed, 26 Jun 2013 06:18:10 -0500
From: James Jones <[email protected]>
Subject: [Haskell-beginners] what to do about excess memory usage
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I finally got serious about learning Haskell and have started by trying
to write as efficient and clear a program to solve the Code Jam 2013
"Fair and Square" problem as I can. (Since the qualifying round is long
over, I have "cheated" some; I peeked at the analysis to see what I had
missed when working on it by myself, and borrowed some very nice
semilattice tree search code by Twan van Laarhoven and an integer square
root routine.) You can see the result at http://pastebin.com/JuyaNLRp
(apologies for what pastebin's Haskell source highlighting does when you
have an identifier with an apostrophe).
The result now processes the test input with values up to a googol in
about 0.2 seconds on my not particularly high-end computer. I'd say
that's as good as I can do and go on to the next problem, but profiling
turns up that
* it's spending 45% of its time garbage collecting. (ouch!)
* one function, pairSum, is consuming a lot of RAM--about two megabytes
at the end.
It seems like a simple function. Here it is, along with most of the
things it uses.
**powersOfTen = map (10 ^) [0..]
halfN = n `div` 2
shell = pair 0
memoPair = zipWith (+) powersOfTen
(take halfN (reverse (take n
powersOfTen)))
pair i = memoPair !! i
pairSum xs = foldl' (+) shell (map pair xs)
(pair i gives the matching 1s in the top and bottom half of a palindrome
that has only ones and zeroes; pairsum takes a list of positions of ones
and generates the corresponding palindrome.) I suspect thunks are
accumulating, but I don't know how to get rid of them. I've tried bang
patterns and $!, to no avail. I still haven't wrapped my brain around seq.
There are other things that should be improved about the code, but I
think I can figure those out myself. I've leaned heavily on Chapter 25
of Real World Haskell to get the code to this point, but it's not
getting through to me how to apply its techniques here. Any suggestions
or pointers would be greatly appreciated.
------------------------------
Message: 3
Date: Wed, 26 Jun 2013 15:48:23 +0200
From: Martin Ruderer <[email protected]>
Subject: Re: [Haskell-beginners] Inconsistencies in type inference
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CA+t_wND0Eh3kfO-X_=e5UWo+kCSOz+EL44Y7E8EouQ=wgqu...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Wed, Jun 26, 2013 at 9:47 AM, Frerich Raabe <[email protected]> wrote:
> Am 6/25/2013 8:45 PM, schrieb Brent Yorgey:
>
> I should add that it is recommended to disable the monomorphism
>> restriction, by putting
>>
>> :set -XNoMonomorphismRestriction
>>
>> in your .ghci file. It has very dubious benefits and usually only
>> serves to confuse.
>>
>
> Hm, this is interesting. To me, most of the extensions are in the "crazy
> stuff only the profesionalls use" category - I successfully tip-toed around
> them so far. :-)
>
> Are there other extensions which people would consider to be "generally
> good to have, unless you know a good reason *not* to enable them"?
>
There has been a question about that on stackoverflow which you might find
interesting:
http://stackoverflow.com/questions/10845179/which-haskell-ghc-extensions-should-users-use-avoid
Ciao, Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130626/25a37aa4/attachment-0001.htm>
------------------------------
Message: 4
Date: Wed, 26 Jun 2013 12:35:56 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Inconsistencies in type inference
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Jun 26, 2013 at 09:47:16AM +0200, Frerich Raabe wrote:
> Am 6/25/2013 8:45 PM, schrieb Brent Yorgey:
> >I should add that it is recommended to disable the monomorphism
> >restriction, by putting
> >
> > :set -XNoMonomorphismRestriction
> >
> >in your .ghci file. It has very dubious benefits and usually only
> >serves to confuse.
>
> Hm, this is interesting. To me, most of the extensions are in the
> "crazy stuff only the profesionalls use" category - I successfully
> tip-toed around them so far. :-)
>
> Are there other extensions which people would consider to be
> "generally good to have, unless you know a good reason *not* to
> enable them"?
I don't know of any others in that category. But there are a few
others which are quite innocuous and if the compiler ever suggests you
might like to turn them on, you should not hesitate, in particular
FlexibleInstances and FlexibleContexts.
-Brent
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 60, Issue 37
*****************************************