[Haskell-cafe] Re: ghc on Ubuntu Linux?

2008-05-17 Thread Galchin, Vasili
PS I have always installed ghc first via the Ubuntu package installer
followed by a build from ghc 6.8.2 source!

Vasili


On Sat, May 17, 2008 at 12:01 AM, Galchin, Vasili [EMAIL PROTECTED]
wrote:

 ghc-pkg list gives me 


 [EMAIL PROTECTED]:~$ ghc-pkg list
 /usr/local/lib/ghc-6.8.2/package.conf:
 Cabal-1.2.3.0, GLUT-2.1.1.1, HUnit-1.2.0.0, OpenGL-2.2.1.1,
 QuickCheck-1.1.0.0, array-0.1.0.0, base-3.0.1.0,
 bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.1,
 directory-1.0.0.0, fgl-5.4.1.1, filepath-1.1.0.0, (ghc-6.8.2),
 haskell-src-1.0.1.1, haskell98-1.0.1.0, hpc-0.5.0.0, html-1.0.1.1,
 mtl-1.1.0.0, network-2.1.0.0, old-locale-1.0.0.0, old-time-1.0.0.0,
 packedstring-0.1.0.0, parallel-1.0.0.0, parsec-2.1.0.0,
 pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0, readline-1.0.1.0,
 regex-base-0.72.0.1, regex-compat-0.71.0.1, regex-posix-0.72.0.2,
 rts-1.0, stm-2.1.1.0, template-haskell-2.2.0.0, time-1.1.2.0,
 unix-2.3.0.0, xhtml-3000.0.2.1


 I am using version ghc-6.8.2.


 V


 On Fri, May 16, 2008 at 11:51 PM, Galchin, Vasili [EMAIL PROTECTED]
 wrote:

 Hello,

  I am running ghc and tools on Ubuntu. I seem to be running into very
 strange problems between ghc-pkg and the Ubuntu package manager. Suddenly
 runhaskell Setup.hs configure just stops working ... Are any other
 ghc/Ubuntu users running into problems? If so, please tell me what problems.
 This is killing my Haskell work!

 Regards, Vasili



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Short circuiting and the Maybe monad

2008-05-17 Thread David Menendez
On Sat, May 17, 2008 at 1:24 AM, Kim-Ee Yeoh [EMAIL PROTECTED] wrote:


 Dan Piponi-2 wrote:

 In fact, you can use the Reader monad as a fixed size container monad.


 Interesting that you say that. Reader seems to me more as an anti-container
 monad.

You just have to think of the environment as an address into an
implicit structure. For example, Bool - a is isomorphic to (a,a).
Thus,

data Diag a = D { p1 :: a, p2 :: a }

to :: Diag a - (Bool - a)
to (D a b) p = if p then a else b

from :: (Bool - a) - Diag a
from f = D (f True) (f False)

Some transformations applied to the monad instance for ((-) Bool) gets you:

instance Monad Diag where
return x   = D x x
D a b = f = D (p1 (f a), p2 (f b))

This works for any enumeration.

Here's a more complex example,

data Stream a = a : Stream a
type Nat = Integer
   -- we'll pretend this can't ever be negative

to :: Stream a - (Nat - a)
to (a : as) 0 = a
to (a : as) n = to as n

from :: (Nat - a) - Stream a
from f = go 0 where go n = f n : go (n + 1)

shead (a : as) = a
stail (a : as) = as

instance Monad Stream where
return x = x : return x
(a : as) = f = shead (f a) : (as = stail . f)

Assuming I haven't mistyped anything,

   to (m = f) n = to (f (to m n)) n

-- 
Dave Menendez [EMAIL PROTECTED]
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Write Haskell as fast as C.

2008-05-17 Thread Ketil Malde
Don Stewart [EMAIL PROTECTED] writes:

 mkAnn :: ByteString - Annotation
 mkAnn = pick . B.words
 where pick (_db:up:rest) = pick' up $ getGo rest
   pick' up' (go:_:ev:_) = Ann (B.copy up') (read $ B.unpack go) 
 (read $ B.unpack ev)
   getGo = dropWhile (not . B.isPrefixOf (pack GO:))

 read $ B.unpack go

 Looks suspicious. You're unpacking to lists.

 ByteString performance rule 1: don't unpack to lists.

I tend to use this idiom a bit when I want to loop over the
characters.  The strings being unpacked is an Int and a short (two or
three letter) identifier.  Doing a 'go' loop would probably be faster,
but a lot more work, and I was hoping the String would be deforested
or fused or otherwise optimized to the bone.

I wonder if the culprit is the last 'read', it reads one from a set of
keywords/identifiers, and since they're upper case, I just made a data
type with a matching set of nullary constructors, and derived Read
for it.

I.e:

 data EvidenceCode = IAC | IUG | IFR | NAC | NR | ... deriving Show

Could it be that this derived read instance is somehow very inefficient?

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Couple of formal questions

2008-05-17 Thread Dominic Steinitz
Creighton Hogg wchogg at gmail.com writes:

 Where could I find a proof that the initial algebras  final coalgebras of CPO
 coincide?  I saw this referenced in the Bananas.. paper as a fact, but am 
 not
 sure where this comes from

Creighton,

As promised and I hope this is what you were after.

Dominic.

http://idontgetoutmuch.wordpress.com/2008/05/12/isomorphic-types/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: ghc on Ubuntu Linux?

2008-05-17 Thread Josef Svenningsson
Vasili,

I have pretty much exactly the same set up as you seem to have. I
haven't had a single problem with running configure using cabal. In
what sense does it stop working?

Cheers,

Josef

2008/5/17 Galchin, Vasili [EMAIL PROTECTED]:
 PS I have always installed ghc first via the Ubuntu package installer
 followed by a build from ghc 6.8.2 source!

 Vasili


 On Sat, May 17, 2008 at 12:01 AM, Galchin, Vasili [EMAIL PROTECTED]
 wrote:

 ghc-pkg list gives me 


 [EMAIL PROTECTED]:~$ ghc-pkg list
 /usr/local/lib/ghc-6.8.2/package.conf:
 Cabal-1.2.3.0, GLUT-2.1.1.1, HUnit-1.2.0.0, OpenGL-2.2.1.1,
 QuickCheck-1.1.0.0, array-0.1.0.0, base-3.0.1.0,
 bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.1,
 directory-1.0.0.0, fgl-5.4.1.1, filepath-1.1.0.0, (ghc-6.8.2),
 haskell-src-1.0.1.1, haskell98-1.0.1.0, hpc-0.5.0.0, html-1.0.1.1,
 mtl-1.1.0.0, network-2.1.0.0, old-locale-1.0.0.0, old-time-1.0.0.0,
 packedstring-0.1.0.0, parallel-1.0.0.0, parsec-2.1.0.0,
 pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0, readline-1.0.1.0,
 regex-base-0.72.0.1, regex-compat-0.71.0.1, regex-posix-0.72.0.2,
 rts-1.0, stm-2.1.1.0, template-haskell-2.2.0.0, time-1.1.2.0,
 unix-2.3.0.0, xhtml-3000.0.2.1


 I am using version ghc-6.8.2.


 V

 On Fri, May 16, 2008 at 11:51 PM, Galchin, Vasili [EMAIL PROTECTED]
 wrote:

 Hello,

  I am running ghc and tools on Ubuntu. I seem to be running into very
 strange problems between ghc-pkg and the Ubuntu package manager. Suddenly
 runhaskell Setup.hs configure just stops working ... Are any other
 ghc/Ubuntu users running into problems? If so, please tell me what problems.
 This is killing my Haskell work!

 Regards, Vasili



 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: ghc on Ubuntu Linux?

2008-05-17 Thread Galchin, Vasili
Josef,

  Did you consistently only use the Ubuntu package manager to install
and upgrade all ghc tools including the compiler, cabal?Or did you ever
build the ghc compiler from source on your system on top of a Ubuntu package
installed ghc like I did?

Vasili

On Sat, May 17, 2008 at 5:01 AM, Josef Svenningsson 
[EMAIL PROTECTED] wrote:

 Vasili,

 I have pretty much exactly the same set up as you seem to have. I
 haven't had a single problem with running configure using cabal. In
 what sense does it stop working?

 Cheers,

 Josef

 2008/5/17 Galchin, Vasili [EMAIL PROTECTED]:
  PS I have always installed ghc first via the Ubuntu package installer
  followed by a build from ghc 6.8.2 source!
 
  Vasili
 
 
  On Sat, May 17, 2008 at 12:01 AM, Galchin, Vasili [EMAIL PROTECTED]
  wrote:
 
  ghc-pkg list gives me 
 
 
  [EMAIL PROTECTED]:~$ ghc-pkg list
  /usr/local/lib/ghc-6.8.2/package.conf:
  Cabal-1.2.3.0, GLUT-2.1.1.1, HUnit-1.2.0.0, OpenGL-2.2.1.1,
  QuickCheck-1.1.0.0, array-0.1.0.0, base-3.0.1.0,
  bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.1,
  directory-1.0.0.0, fgl-5.4.1.1, filepath-1.1.0.0, (ghc-6.8.2),
  haskell-src-1.0.1.1, haskell98-1.0.1.0, hpc-0.5.0.0, html-1.0.1.1,
  mtl-1.1.0.0, network-2.1.0.0, old-locale-1.0.0.0, old-time-1.0.0.0,
  packedstring-0.1.0.0, parallel-1.0.0.0, parsec-2.1.0.0,
  pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0, readline-1.0.1.0,
  regex-base-0.72.0.1, regex-compat-0.71.0.1, regex-posix-0.72.0.2,
  rts-1.0, stm-2.1.1.0, template-haskell-2.2.0.0, time-1.1.2.0,
  unix-2.3.0.0, xhtml-3000.0.2.1
 
 
  I am using version ghc-6.8.2.
 
 
  V
 
  On Fri, May 16, 2008 at 11:51 PM, Galchin, Vasili [EMAIL PROTECTED]
  wrote:
 
  Hello,
 
   I am running ghc and tools on Ubuntu. I seem to be running into
 very
  strange problems between ghc-pkg and the Ubuntu package manager.
 Suddenly
  runhaskell Setup.hs configure just stops working ... Are any other
  ghc/Ubuntu users running into problems? If so, please tell me what
 problems.
  This is killing my Haskell work!
 
  Regards, Vasili
 
 
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: ghc on Ubuntu Linux?

2008-05-17 Thread Achim Schneider
Galchin, Vasili [EMAIL PROTECTED] wrote:

 Did you consistently only use the Ubuntu package manager to
 install and upgrade all ghc tools including the compiler, cabal?Or
 did you ever build the ghc compiler from source on your system on top
 of a Ubuntu package installed ghc like I did?
 
 
 On Sat, May 17, 2008 at 5:01 AM, Josef Svenningsson 
 [EMAIL PROTECTED] wrote:
 
  I have pretty much exactly the same set up as you seem to have. I
  haven't had a single problem with running configure using cabal. In
  what sense does it stop working?
 

SCNR, who is asking questions here?


btw: please stop that TOFU

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] A point in favour of -XOverlappingInstances (and -XTypeSynonymInstances)

2008-05-17 Thread Achim Schneider
Token.hs:103:15:
Overlapping instances for Show (SourcePos, Tok)
  arising from a use of `anyToken' at Token.hs:103:15-22
Matching instances:
  instance (Show a, Show b) = Show (a, b) -- Defined in GHC.Show
  instance [overlap ok] Show Token
-- Defined at Token.hs:(39,0)-(40,23)

I was just trying _not_ to show the a of (a,b)

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Performance: MD5

2008-05-17 Thread Andrew Coppin

Hi folks.

OK, try this:

 darcs get http://darcs.orphi.me.uk/MyMD5
 cd MyMD5
 ghc -O2 --make md5sum
 md5sum some large filename

On my PC, it takes 3.5 seconds to compute the MD5 hash of a 10 MB file. 
For comparison, the md5.exe I downloaded from the Internet does it 
instantaneously. It's literally so fast I can't even time it. As far as 
I know, my program always produces the *correct* answer, it just takes 
far too long to do it.


If anybody has any interesting insights as to why my version is so 
damned slow, I'd like to hear them. (Indeed, a description of the 
process for tracking the problem down would also be useful!)


[Much to my bemusement, when I had a look at the code, I discovered that 
tucked away in a corner somewhere, it reads a ByteString from disk and 
instantly converts it to [Word8]. Uh... oops? Anyway, eliminating this 
changed the numbers I get from the profiler, but it's still far too slow.]


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Performance: MD5

2008-05-17 Thread Bulat Ziganshin
Hello Andrew,

Saturday, May 17, 2008, 6:51:27 PM, you wrote:

 If anybody has any interesting insights as to why my version is so
 damned slow, I'd like to hear them.

i equally will be interesting to hear why you think what your program
should be as fast as C version? you wrote it in purely functional
style. as Don wrote, if you want to reach unoptimized C-like
performance, you need to write in C style - with explicit loop
processing primitive types. so

1) -funbox-strict-fields
2) don't use tuples as arguments - they are lazy. you may implement
strict tuples instead
3) function as a parameter is very bad unless it will be inlined

but these are only half-decisions. if you need maximum efficiency,
drop all this high-level code and map md5.c to haskell as it was done
in Don's bloag


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Performance: MD5

2008-05-17 Thread Thomas M. DuBuisson
Andrew,
I spent a reasonable amount of time making pureMD5 (available on
hackage) faster, which mainly ment strictness annoitations and unboxing
strict fields, but I also spent a good deal of time with the profiler.
One of my early versions was fairly slow due to the converting of the
LPS to blocks (an Isabelle proven 'blocks' function) caused O(n) space
requirement.  I've been meaning to revisit this to optimize more and
look closly at GHC core.

I'm on vacation now, but when I get back I'll try to make time to look
at your code (unless its moot by then).  Finally, I encourage anyone
interested to make reasonably fast bytestring implementations of SHA
algorithms as well - Haskell/Hackage has a number of pure and FFI
implementations of MD5 but is a bit lacking in any other cryptographic
algorithm.

TomMD

On Sat, 2008-05-17 at 15:51 +0100, Andrew Coppin wrote:
 Hi folks.
 
 OK, try this:
 
   darcs get http://darcs.orphi.me.uk/MyMD5
   cd MyMD5
   ghc -O2 --make md5sum
   md5sum some large filename
 
 On my PC, it takes 3.5 seconds to compute the MD5 hash of a 10 MB file. 
 For comparison, the md5.exe I downloaded from the Internet does it 
 instantaneously. It's literally so fast I can't even time it. As far as 
 I know, my program always produces the *correct* answer, it just takes 
 far too long to do it.
 
 If anybody has any interesting insights as to why my version is so 
 damned slow, I'd like to hear them. (Indeed, a description of the 
 process for tracking the problem down would also be useful!)
 
 [Much to my bemusement, when I had a look at the code, I discovered that 
 tucked away in a corner somewhere, it reads a ByteString from disk and 
 instantly converts it to [Word8]. Uh... oops? Anyway, eliminating this 
 changed the numbers I get from the profiler, but it's still far too slow.]
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A point in favour of -XOverlappingInstances (and -XTypeSynonymInstances)

2008-05-17 Thread Duncan Coutts
On Sat, 2008-05-17 at 15:12 +0200, Achim Schneider wrote:
 Token.hs:103:15:
 Overlapping instances for Show (SourcePos, Tok)
   arising from a use of `anyToken' at Token.hs:103:15-22
 Matching instances:
   instance (Show a, Show b) = Show (a, b) -- Defined in GHC.Show
   instance [overlap ok] Show Token
 -- Defined at Token.hs:(39,0)-(40,23)
 
 I was just trying _not_ to show the a of (a,b)

A point in favour of newtypes

newtype Token = Token (SourcePos, Tok)
instance Show Token where
  ...

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] another Newbie performance question

2008-05-17 Thread Philip Müller

Hi everybody,

I was doing an assignment in Java for my university concerning a program 
that reads, modifies and writes CSV files, when I suddenly had the idea 
of implementing parts of this in Haskell for fun.


When I finished the Haskell programm, I was disappointed by the performance:
To parse a 200k lines CSV file, insert a line (yes I know i could insert 
a line without parsing the file, that's just an example) at pos. 19 
and write the file again, the Java program takes 1.1 seconds while the 
Haskell program takes 12.5 seconds.


I have read Don's blog post but am unsure how to implement his tips into 
my program, as I am still kind of a Haskell beginner.


The source code (40 lines incl. comments and empty lines) and the 200k 
CSV file I used for testing and a smaller CSV file demonstrating the 
special easy-to-parse CSV syntax are available on my ftp server,


ftp://baah.servegame.org/public/haskell

The call syntax is
program csv file line to insert
e.g.
main lang.csv test,this,line

I haven't posted the source code here directly because I thought it 
might be too long.


If someone here finds the time to look at my code and give me some 
hints, that would really be nice.



Regards
Philip
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Another optimization question

2008-05-17 Thread John Dorsey
Jeroen,

 isPrime :: Int - Bool
 isPrime x = isPrime' x primes
 where isPrime' x (p:ps) | x == p = True
 | x  p = isPrime' x ps
 | otherwise = False
 
 main = print $ length (filter (== True) (map isPrime [1..5000]))
[...]
 isPrime x = elem x (takeWhile (= x) primes)

Here's a couple of things, although I don't know if they account for what
you're seeing.  All code is untested.

1)  A simpler main would be:

main = print $ length $ filter isPrime [1..5000]

This version manually fuses your map and filter.  Of course it's not
the same if you're doing anything else besides 'length'.

2)  The takeWhile in your second isPrime creates a throwaway list, which
doesn't exist in the explicit-recursion isPrime.  Unless this gets
optimized out, this could be the droid you're looking for.  I'd compile
with profiling (ghc -O2 --make -prof -auto-all experiment2), and run
./experiment2 +RTS -p -s
Find profiling stats in experiment2.prof, and check whether the latter
version isn't allocating a lot more.  When you feel like Core-diving,
it's something specific to look for.

3)  Maybe you can get the best of your two versions -- meaning the
relative speed of the first and functional style of the second -- by
writing your own 'elem' replacement that works on a sorted list.
Something like this, with suitably defined elemAsc:

-- elemAsc: tests presence of element in an ascending list
elemAsc :: (Ord a) = a - [a] - Bool
elemAsc ...
isPrime x = elemAsc x primes

Here's a good habit:  abstract things like this out.  Read the
libraries, and look for better and more abstract patterns.
Rinse, repeat.

4)  This doesn't explain why the version with real primes was 10x slower.
Are you comparing apples to apples?  Specifically, comparing both
versions of isPrime above using real primes, so both of them have to
create the primes list?  Does your code for real primes still use [Int]
and not [Integer] or (Num t) = [t] ?

I haven't invested the time yet to stare at GHC Core until it clicks,
excepting a few snippets that have been discussed here.  I'm not sure
how early in the learning curve it's advisable.  Probably depends on
your background.

Good luck Eulering,
John

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Another optimization question

2008-05-17 Thread anton muhin
On Sat, May 17, 2008 at 8:19 PM, Jeroen [EMAIL PROTECTED] wrote:
 Hi, I know there's been quite some performance/optimization post lately,
 so I hope there still room for one more. While solving a ProjectEuler
 problem (27), I saw a performance issue I cannot explain. I narrowed it
 down to the following code (never mind that 'primes' is just [1..],
 the problem is the same or worse with real primes):

 primes :: [Int]
 primes = [1..]

 isPrime :: Int - Bool
 isPrime x = isPrime' x primes
where isPrime' x (p:ps) | x == p = True
| x  p = isPrime' x ps
| otherwise = False

 main = print $ length (filter (== True) (map isPrime [1..5000]))

 $ time ./experiment1
 5000

 real0m4.037s
 user0m3.378s
 sys 0m0.060s


 All good, but if I change isPrime to the simpeler

 isPrime x = elem x (takeWhile (= x) primes)

 it takes twice as long:

 time ./experiment2
 5000

 real0m7.837s
 user0m6.532s
 sys 0m0.141s

 With real primes, it even takes 10 times as long.
 I tried looking at the output of ghc -ddump-simpl,
 as suggested in a previous post, but it's a bit over
 my head (newby here...).

 Any suggestions?

Just a thought: in your first approach you compare any element of the
list once.  In second---twice: once to check if = x and second time
to check if it is equal to x.  That's a hypothesis, but another
implementation of isPrime:

isPrime x = (== x) $ head $ dropWhile ( x) primes

seems to behave closer to your first version than to the second.  Note
that that does unnecessary comparison as well the find first element
= x.

yours,
anton.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: another Newbie performance question

2008-05-17 Thread Achim Schneider
Philip Müller [EMAIL PROTECTED] wrote:

 I have read Don's blog post but am unsure how to implement his tips
 into my program, as I am still kind of a Haskell beginner.
 
Dan, you seem to have opened a big can of worms. If Haskell is
successful, it's your fault.

Without doing any compiling, staring at core nor profiling myself, I
advice that you

1) traverse the list less often. 
2) use ByteStrings
3) use an intermediate data structure that has better insert behaviour
than a standard list, have a look at Data.Sequence
4) really, really use ByteStrings
5) listen to me if I tell you to use ByteStrings
6) if you already must write in pointless style, please don't also
order the functions in a backward way.


-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Another optimization question

2008-05-17 Thread Daniel Fischer
Am Samstag, 17. Mai 2008 19:52 schrieb anton muhin:
 On Sat, May 17, 2008 at 8:19 PM, Jeroen [EMAIL PROTECTED] wrote:
  Hi, I know there's been quite some performance/optimization post lately,
  so I hope there still room for one more. While solving a ProjectEuler
  problem (27), I saw a performance issue I cannot explain. I narrowed it
  down to the following code (never mind that 'primes' is just [1..],
  the problem is the same or worse with real primes):
 
  primes :: [Int]
  primes = [1..]
 
  isPrime :: Int - Bool
  isPrime x = isPrime' x primes
 where isPrime' x (p:ps) | x == p = True
 
 | x  p = isPrime' x ps
 | otherwise = False
 
  main = print $ length (filter (== True) (map isPrime [1..5000]))
 
  $ time ./experiment1
  5000
 
  real0m4.037s
  user0m3.378s
  sys 0m0.060s
 
 
  All good, but if I change isPrime to the simpeler
 
  isPrime x = elem x (takeWhile (= x) primes)
 
  it takes twice as long:
 
  time ./experiment2
  5000
 
  real0m7.837s
  user0m6.532s
  sys 0m0.141s
 
  With real primes, it even takes 10 times as long.
  I tried looking at the output of ghc -ddump-simpl,
  as suggested in a previous post, but it's a bit over
  my head (newby here...).
 
  Any suggestions?

 Just a thought: in your first approach you compare any element of the
 list once.  In second---twice: once to check if = x and second time
 to check if it is equal to x.  That's a hypothesis,

I thought so, too, but I couldn't reproduce the behaviour, so I'm not sure 
what happens. In fact, compiling without optimisations, the first version 
takes almost twice as long as the second. Compiled with -O2, the second takes 
about 13% more time.

Using a real list of primes,
[EMAIL PROTECTED]:~/EulerProblems/Testing ghc --make experiment -o experiment3
[1 of 1] Compiling Main ( experiment.hs, experiment.o )
Linking experiment3 ...
[EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment3
669

real0m0.222s
user0m0.220s
sys 0m0.000s
[EMAIL PROTECTED]:~/EulerProblems/Testing ghc --make experiment -o experiment4
[1 of 1] Compiling Main ( experiment.hs, experiment.o )
Linking experiment4 ...
[EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment4
669

real0m0.299s
user0m0.290s
sys 0m0.000s

But
[EMAIL PROTECTED]:~/EulerProblems/Testing ghc -O2 --make experiment -o 
experiment3
[1 of 1] Compiling Main ( experiment.hs, experiment.o )
Linking experiment3 ...
[EMAIL PROTECTED]:~/EulerProblems/Testing ghc -O2 --make experiment -o 
experiment4
[1 of 1] Compiling Main ( experiment.hs, experiment.o )
Linking experiment4 ...
[EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment3
669

real0m0.053s
user0m0.040s
sys 0m0.010s
[EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment4
669

real0m0.257s
user0m0.250s
sys 0m0.010s

Wow! 
I've no idea what optimising did to the first version, but apparently it 
couldn't do much for the second.

 but another
 implementation of isPrime:

 isPrime x = (== x) $ head $ dropWhile ( x) primes

With -O2, this is about 20% slower than the Jeroen's first version, without 
optimisations 50% faster.
Strange.
isPrime :: Int - Bool
isPrime x = go primes
  where
go (p:ps) = case compare x p of
LT - False
EQ - True
GT - go ps

does best (on my box), with and without optimisations (very very slightly with 
-O2) for a list of real primes, but not for [1 .. ].

However, more than can be squished out of fiddling with these versions could 
be gained from a better algorithm.

 seems to behave closer to your first version than to the second.  Note
 that that does unnecessary comparison as well the find first element

 = x.

 yours,
 anton.

perplexed,
Daniel

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Write Haskell as fast as C.

2008-05-17 Thread Martin Geisler
Andrew Coppin [EMAIL PROTECTED] writes:

 Look closer: it's hardER to read.

  mean xs = sum xs / fromIntegral (length xs)

  mean = go 0 0 n
where
  go s l x
| x  m = s / fromIntegra l
| otherwise = go (s+x) (l+1) (x+1

 One version makes it instantly clear, at a glance, what is happening.
 The other requires you to mentally walk round a look, imperative
 style, to figure out what's happening. It's not a *big* deal, but it's
 unfortunate.

I am new to Haskell and when I first saw the two versions side by side I
too was disappointed with the second version.

But after reading the great blog post by Don, I realized that the whole
problem comes from the fact that lists in Haskell are not like arrays or
vectors in other languages: you don't know how long they are before you
have found the end.

In other words: they behave like a linked lists -- lists that are
generated lazily on demand. Because they are generated on demand you
*cannot* really know the length beforehand, and thus you *must* traverse
the list to its end to count the length.

When the list is too big to fit in memory then it's clear that the code
*must* let go of the beginning to allow the garbage collector to do its
job. You wouldn't be able to work with a 7.5 GiB linked list otherwise.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.


pgpgElb902o1M.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell-Cafe Info Page

2008-05-17 Thread D. Gregor

Hello,

Common Lisp is a multiparadigm, general purpose programming language  
that supports imperative, functional, and object-oriented programming  
paradigms.  Haskell is purely functional.  Is this a reason why there  
is not macro feature in Haskell?  I feel the object-oriented paradigm  
of CL and Scheme is the reason for the macro feature in these two  
languages.  If it's not, then what does the macro feature provide, and  
why isn't it in Haskell?


Douglas___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell-Cafe Info Page

2008-05-17 Thread Brandon S. Allbery KF8NH


On 2008 May 17, at 14:52, D. Gregor wrote:

Common Lisp is a multiparadigm, general purpose programming language  
that supports imperative, functional, and object-oriented  
programming paradigms.  Haskell is purely functional.  Is this a  
reason why there is not macro feature in Haskell?  I feel the object- 
oriented paradigm of CL and Scheme is the reason for the macro  
feature in these two languages.  If it's not, then what does the  
macro feature provide, and why isn't it in Haskell?


Macros in Lisp have less to do with functional vs. non-functional than  
with programs and data having precisely the same form (s-expressions).


There is a macro facility of the kind you're thinking of in Haskell  
(Template Haskell), but you have to work with abstract syntax tables  
which look nothing like the original code.


--
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 universityKF8NH


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell-Cafe Info Page

2008-05-17 Thread Don Stewart
allbery:
On 2008 May 17, at 14:52, D. Gregor wrote:
 
  Common Lisp is a multiparadigm, general purpose programming language
  that supports imperative, functional, and object-oriented programming
  paradigms.  Haskell is purely functional.  Is this a reason why there is
  not macro feature in Haskell?  I feel the object-oriented paradigm of CL
  and Scheme is the reason for the macro feature in these two languages.
   If it's not, then what does the macro feature provide, and why isn't it
  in Haskell?
 
Macros in Lisp have less to do with functional vs. non-functional than
with programs and data having precisely the same form (s-expressions).
There is a macro facility of the kind you're thinking of in Haskell
(Template Haskell), but you have to work with abstract syntax tables which
look nothing like the original code.

Also, laziness is used for many of the coding jobs you might use macros
for. So there's less need for macros.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell-Cafe Info Page

2008-05-17 Thread Denis Bueno
On Sat, May 17, 2008 at 3:16 PM, Don Stewart [EMAIL PROTECTED] wrote:
 allbery:
On 2008 May 17, at 14:52, D. Gregor wrote:

  Common Lisp is a multiparadigm, general purpose programming language
  that supports imperative, functional, and object-oriented programming
  paradigms.  Haskell is purely functional.  Is this a reason why there is
  not macro feature in Haskell?  I feel the object-oriented paradigm of CL
  and Scheme is the reason for the macro feature in these two languages.
   If it's not, then what does the macro feature provide, and why isn't it
  in Haskell?

Macros in Lisp have less to do with functional vs. non-functional than
with programs and data having precisely the same form (s-expressions).
There is a macro facility of the kind you're thinking of in Haskell
(Template Haskell), but you have to work with abstract syntax tables which
look nothing like the original code.

 Also, laziness is used for many of the coding jobs you might use macros
 for. So there's less need for macros.

Precisely so.  For example, macros are often used to implement control
operators (e.g. specific kinds of complicated iteration), which is
easily done in haskell with normal functions, due to laziness.

-- 
 Denis
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Mapping Haskell Concepts To C# 3

2008-05-17 Thread Kaveh Shahbazian
I have question on mapping some Haskell concepts to C# 3 ones. Maybe there
are not any strict equivalents; yet it helps:

1 - What is the equivalent of Type Constructor in C#?
2 - What is the equivalent of Data Constructor in C#?
3 - What is the logical implementation of pattern matching in C#? (For
example using structures with indicator fields or using interfaces and
inheritance and dynamically dispatch in calling overloaded methods. Also
this question contain a hidden one...GADTs!)

Best Regards

-- 
Kaveh Shahbazian
email: [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mapping Haskell Concepts To C# 3

2008-05-17 Thread Sebastian Sylvan
2008/5/17 Kaveh Shahbazian [EMAIL PROTECTED]:

 I have question on mapping some Haskell concepts to C# 3 ones. Maybe there
 are not any strict equivalents; yet it helps:

 1 - What is the equivalent of Type Constructor in C#?


Class declaration. Generic ones. E.g. Listint, is a type where the type
constructor List has been applied to the type int.



 2 - What is the equivalent of Data Constructor in C#?


Constructors, I guess.



 3 - What is the logical implementation of pattern matching in C#? (For
 example using structures with indicator fields or using interfaces and
 inheritance and dynamically dispatch in calling overloaded methods. Also
 this question contain a hidden one...GADTs!)


You can use an abstract base class, and then inherit one class for each
constructor (e.g. base class Expression, and concrete subclasses Mul, Add,
etc.). Then you can use runtime type reflection to figure out which kind of
Expression you have and branch on it.



-- 
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Calling haddock in a portable way

2008-05-17 Thread Misha Aizatulin

hello,

  the new version of haddock (2.0.0) needs a new option -B that tells 
it  the GHC lib directory. How do I find out the correct value for this 
option in a makefile, so that the makefile stays portable?


Cheers,
  Misha
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [ANN] Next Bay FP Meeting: Bryan O'Sullivan on Concurrent and multicore programming in Haskell

2008-05-17 Thread Keith Fahlgren

On 5/2/08 8:50 PM, Vimal wrote:

On 03/05/2008, Keith Fahlgren [EMAIL PROTECTED] wrote:

Hi,


 Our next BayFP meeting will be this Thursday, May 8th, 2008 at 7:30pm.
 We'll feature Bryan O'Sullivan on Concurrent and multicore programming
 in Haskell. Bryan is a co-author of the upcoming O'Reilly book Real


Cant wait for the video! How long before the video comes up on the website?


The video is now available: 
http://www.bayfp.org/blog/2008/05/17/video-and-slides-from-bryan-o%e2%80%99sullivans-talk/


HTH,
Keith
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Another optimization question

2008-05-17 Thread anton muhin
On Sat, May 17, 2008 at 10:40 PM, Daniel Fischer
[EMAIL PROTECTED] wrote:
 Am Samstag, 17. Mai 2008 19:52 schrieb anton muhin:
 On Sat, May 17, 2008 at 8:19 PM, Jeroen [EMAIL PROTECTED] wrote:
  Hi, I know there's been quite some performance/optimization post lately,
  so I hope there still room for one more. While solving a ProjectEuler
  problem (27), I saw a performance issue I cannot explain. I narrowed it
  down to the following code (never mind that 'primes' is just [1..],
  the problem is the same or worse with real primes):
 
  primes :: [Int]
  primes = [1..]
 
  isPrime :: Int - Bool
  isPrime x = isPrime' x primes
 where isPrime' x (p:ps) | x == p = True
 
 | x  p = isPrime' x ps
 | otherwise = False
 
  main = print $ length (filter (== True) (map isPrime [1..5000]))
 
  $ time ./experiment1
  5000
 
  real0m4.037s
  user0m3.378s
  sys 0m0.060s
 
 
  All good, but if I change isPrime to the simpeler
 
  isPrime x = elem x (takeWhile (= x) primes)
 
  it takes twice as long:
 
  time ./experiment2
  5000
 
  real0m7.837s
  user0m6.532s
  sys 0m0.141s
 
  With real primes, it even takes 10 times as long.
  I tried looking at the output of ghc -ddump-simpl,
  as suggested in a previous post, but it's a bit over
  my head (newby here...).
 
  Any suggestions?

 Just a thought: in your first approach you compare any element of the
 list once.  In second---twice: once to check if = x and second time
 to check if it is equal to x.  That's a hypothesis,

 I thought so, too, but I couldn't reproduce the behaviour, so I'm not sure
 what happens. In fact, compiling without optimisations, the first version
 takes almost twice as long as the second. Compiled with -O2, the second takes
 about 13% more time.

Why not -O3?

 Using a real list of primes,
What's the size of the real list?

 [EMAIL PROTECTED]:~/EulerProblems/Testing ghc --make experiment -o 
 expleriment3
 [1 of 1] Compiling Main ( experiment.hs, experiment.o )
 Linking experiment3 ...
 [EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment3
 669

 real0m0.222s
 user0m0.220s
 sys 0m0.000s
 [EMAIL PROTECTED]:~/EulerProblems/Testing ghc --make experiment -o 
 experiment4
 [1 of 1] Compiling Main ( experiment.hs, experiment.o )
 Linking experiment4 ...
 [EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment4
 669

 real0m0.299s
 user0m0.290s
 sys 0m0.000s

 But
 [EMAIL PROTECTED]:~/EulerProblems/Testing ghc -O2 --make experiment -o 
 experiment3
 [1 of 1] Compiling Main ( experiment.hs, experiment.o )
 Linking experiment3 ...
 [EMAIL PROTECTED]:~/EulerProblems/Testing ghc -O2 --make experiment -o 
 experiment4
 [1 of 1] Compiling Main ( experiment.hs, experiment.o )
 Linking experiment4 ...
 [EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment3
 669

 real0m0.053s
 user0m0.040s
 sys 0m0.010s
 [EMAIL PROTECTED]:~/EulerProblems/Testing time ./experiment4
 669

 real0m0.257s
 user0m0.250s
 sys 0m0.010s

 Wow!
 I've no idea what optimising did to the first version, but apparently it
 couldn't do much for the second.

 but another
 implementation of isPrime:

 isPrime x = (== x) $ head $ dropWhile ( x) primes

 With -O2, this is about 20% slower than the Jeroen's first version, without
 optimisations 50% faster.
 Strange.

Well, head has its overhead as well.  Cf. two variants:

firstNotLess :: Int - [Int] - Int
firstNotLess s (x:xs) = if x  s then firstNotLess s xs else x

dropLess :: Int - [Int] - [Int]
dropLess s l@(x:xs) = if x  s then dropLess s xs else l

isPrime :: Int - Bool
isPrime x = x == (firstNotLess x primes)

isPrime' :: Int - Bool
isPrime' x = x == (head $ dropLess x primes)

On my box firstNotLess gives numbers pretty close (if not better) than
Jeroen's first variant, while head $ dropLess notably worse.

 isPrime :: Int - Bool
 isPrime x = go primes
  where
go (p:ps) = case compare x p of
LT - False
EQ - True
GT - go ps

 does best (on my box), with and without optimisations (very very slightly with
 -O2) for a list of real primes, but not for [1 .. ].

And what happens for [1..]?

 However, more than can be squished out of fiddling with these versions could
 be gained from a better algorithm.
Definitely.

yours,
anton.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Another optimization question

2008-05-17 Thread Brandon S. Allbery KF8NH


On 2008 May 17, at 16:48, anton muhin wrote:

Why not -O3?


-O3 doesn't do anything over -O2 in ghc.  -fvia-c -optc-O3 *might* be  
an improvement, or might not.


--
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 universityKF8NH


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Calling haddock in a portable way

2008-05-17 Thread Gwern Branwen
On 2008.05.17 21:54:53 +0200, Misha Aizatulin [EMAIL PROTECTED] scribbled 
0.2K characters:
 hello,

   the new version of haddock (2.0.0) needs a new option -B that tells it
 the GHC lib directory. How do I find out the correct value for this option
 in a makefile, so that the makefile stays portable?

 Cheers,
   Misha

Maybe you could do something like call out to a shell and ask it to run 'ghc 
--print-libdir'? That for me prints to stdout a string like 
'/usr/lib64/ghc-6.8.2'.

--
gwern
Rivera Peering Intiso SAMF facsimile Submarine redheads AHPCRC DJC Sears


pgpPgoYydlwye.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] another Newbie performance question

2008-05-17 Thread Luke Palmer
On Sat, May 17, 2008 at 5:22 PM, Philip Müller
[EMAIL PROTECTED] wrote:
 If someone here finds the time to look at my code and give me some hints,
 that would really be nice.

A little experimentation reveals that your main bottleneck is readCSVLine:

  readCSVLine = read . (\x - [ ++ x ++ ])

(I just replaced it with (:[]) and it sped up enormously)

Thus, I rewrote it myself instead of with read.

readCSVLine   = unfoldr builder
where
builder [] = Nothing
builder xs = Just $ readField xs

readField []   = ([],[])
readField (',':xs) = ([],xs)
readField ('':xs) =
let (l,'':r) = span (/= '') xs
(field,rest) = readField r

And decreased the runtime from 17 seconds to 4.2.  It probably admits
an even better implementation, but it's likely that this is not the
bottleneck anymore.

The other thing is that the whole table is stored in memory because of
your call to length csv in doInteraction.  This may have been the
intent.  But if not, you can cut another 1 second off the runtime by
streaming the file using a function that lazily inserts the line in
the second-to-last position.

insertLine line csv = let (l,r) =
splitLast csv in l ++ [readCSVLine line] ++ r
where
splitLast [x]= ([],[x])
splitLast (x:xs) = let (l,r) = splitLast xs in (x:l,r)

(Note that I got rid of the pos parameter)

Presumably in a real application you are scanning until you see
something and then inserting near that, which is a lazy streamlike
operation.

There are probably a few other tricks you could do, but I think I
identified the main factors.

Luke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Calling haddock in a portable way

2008-05-17 Thread Misha Aizatulin


Maybe you could do something like call out to a shell and ask it to run
'ghc --print-libdir'? That for me prints to stdout a string like
'/usr/lib64/ghc-6.8.2'.

  Yes, this looks like a solution. Thanks a lot!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Another optimization question

2008-05-17 Thread Daniel Fischer
Am Samstag, 17. Mai 2008 22:48 schrieb anton muhin:

 Why not -O3?

As far as I know - and Brandon S.Allbery said so, too - -O3 isn't better than 
-O2.

  Using a real list of primes,

 What's the size of the real list?

arbitrary, however, since it's [Int], it will actually be at most 105097565 
primes long, but since only numbers up to 5000 are checked, only 670 primes 
will ever be considered - When I check numbers 1 to 5 (5133 primes, so 
5134 primes evaluated), with -O0 / -O2, it's
Jeroen 1 : 14.5 s / 2.4 s
Jeroen 2 : 52.5 s / 49.7 s
(== x) . head . dropWhile ( x) : 8.2 s /4.1 s
go primes : 5.5 s / 2.5 s

So Jeroen 1 is the best to be optimised :)

  but another
  implementation of isPrime:
 
  isPrime x = (== x) $ head $ dropWhile ( x) primes
 
  With -O2, this is about 20% slower than the Jeroen's first version,
  without optimisations 50% faster.
  Strange.

 Well, head has its overhead as well.  Cf. two variants:

 firstNotLess :: Int - [Int] - Int
 firstNotLess s (x:xs) = if x  s then firstNotLess s xs else x

 dropLess :: Int - [Int] - [Int]
 dropLess s l@(x:xs) = if x  s then dropLess s xs else l

 isPrime :: Int - Bool
 isPrime x = x == (firstNotLess x primes)

 isPrime' :: Int - Bool
 isPrime' x = x == (head $ dropLess x primes)

 On my box firstNotLess gives numbers pretty close (if not better) than

for primes up to 5, that's
6.8 s / 2.1 s with -O0 / -O2 respectively on mine

 Jeroen's first variant, while head $ dropLess notably worse.

5.8 s / 2.4 s here.

  isPrime :: Int - Bool
  isPrime x = go primes
   where
 go (p:ps) = case compare x p of
 LT - False
 EQ - True
 GT - go ps
 
  does best (on my box), with and without optimisations (very very slightly
  with -O2) for a list of real primes, but not for [1 .. ].

 And what happens for [1..]?

With -O2, Jeroen 1 was best (1.62), nex firstNotLess (1.63), head . dropLess 
(1.74), then in close succesion Jeroen 2 (1.92), go primes (1.96) and head . 
dropWhile (1.99),
with -O0, it's
head . dropWhile (1.7 s, YES, that actually is faster with -O0 than with 
-O2!), head . dropLess (2.0), Jeroen 2 and firstNotLess (2.1 s), go primes 
(2.3 s), Jeroen 1 (3.2 s).

Weirder and weirder.


  However, more than can be squished out of fiddling with these versions
  could be gained from a better algorithm.

 Definitely.

 yours,
 anton.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: ghc on Ubuntu Linux?

2008-05-17 Thread Galchin, Vasili
Hi Josef,

 What generates dist/setup-config? When I run runhaskell Setup.hs
configure, nothing including dist/setup.config gets generated. ??

Regards, Vasili



On Sat, May 17, 2008 at 11:02 AM, Josef Svenningsson 
[EMAIL PROTECTED] wrote:

 On Sat, May 17, 2008 at 1:00 PM, Galchin, Vasili [EMAIL PROTECTED]
 wrote:
  Josef,
 
  E.g.
  [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs
 configure
  Configuring unix-2.3.0.0...
 
  Normally copious output ... ???
 
 That's what it should look like! It just means you have a recent
 version of cabal which doesn't spit out tons of information when
 configuring. Happily all is well.

 /Josef

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] more runhaskell question

2008-05-17 Thread Galchin, Vasili
[EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/mlock$ runhaskell
Setup.lhs configure --prefix=$HOME
Configuring mlock-1.0...
[EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/mlock$ runhaskell
Setup.lhs build
Setup.lhs: error reading dist/setup-config; run setup configure command?

No dist/setup-config is being generated!

what is the setup configure command??

Regards, Vasili
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Another optimization question

2008-05-17 Thread Jeroen
Daniel Fischer daniel.is.fischer at web.de writes:
 
 Am Samstag, 17. Mai 2008 22:48 schrieb anton muhin:
 
  Why not -O3?
 
 As far as I know - and Brandon S.Allbery said so, too - -O3 isn't better than 
 -O2.
 
   Using a real list of primes,
 
  What's the size of the real list?
 
 arbitrary, however, since it's [Int], it will actually be at most 105097565 
 primes long, but since only numbers up to 5000 are checked, only 670 primes 
 will ever be considered - When I check numbers 1 to 5 (5133 primes, so 
 5134 primes evaluated), with -O0 / -O2, it's
 Jeroen 1 : 14.5 s / 2.4 s
 Jeroen 2 : 52.5 s / 49.7 s
 (== x) . head . dropWhile ( x) : 8.2 s /4.1 s
 go primes : 5.5 s / 2.5 s
 
 So Jeroen 1 is the best to be optimised :)
 
   but another
   implementation of isPrime:
  
   isPrime x = (== x) $ head $ dropWhile ( x) primes
  
   With -O2, this is about 20% slower than the Jeroen's first version,
   without optimisations 50% faster.
   Strange.
 
  Well, head has its overhead as well.  Cf. two variants:
 
  firstNotLess :: Int - [Int] - Int
  firstNotLess s (x:xs) = if x  s then firstNotLess s xs else x
 
  dropLess :: Int - [Int] - [Int]
  dropLess s l@(x:xs) = if x  s then dropLess s xs else l
 
  isPrime :: Int - Bool
  isPrime x = x == (firstNotLess x primes)
 
  isPrime' :: Int - Bool
  isPrime' x = x == (head $ dropLess x primes)
 
  On my box firstNotLess gives numbers pretty close (if not better) than
 
 for primes up to 5, that's
 6.8 s / 2.1 s with -O0 / -O2 respectively on mine
 
  Jeroen's first variant, while head $ dropLess notably worse.
 
 5.8 s / 2.4 s here.
 
   isPrime :: Int - Bool
   isPrime x = go primes
where
  go (p:ps) = case compare x p of
  LT - False
  EQ - True
  GT - go ps
  
   does best (on my box), with and without optimisations (very very slightly
   with -O2) for a list of real primes, but not for [1 .. ].
 
  And what happens for [1..]?
 
 With -O2, Jeroen 1 was best (1.62), nex firstNotLess (1.63), head . dropLess 
 (1.74), then in close succesion Jeroen 2 (1.92), go primes (1.96) and head . 
 dropWhile (1.99),
 with -O0, it's
 head . dropWhile (1.7 s, YES, that actually is faster with -O0 than with 
 -O2!), head . dropLess (2.0), Jeroen 2 and firstNotLess (2.1 s), go primes 
 (2.3 s), Jeroen 1 (3.2 s).
 
 Weirder and weirder.
 
 
   However, more than can be squished out of fiddling with these versions
   could be gained from a better algorithm.
 
  Definitely.
 
  yours,
  anton.
 

Thanks for the responses so far!

I only tested with -O2 and my primes implementation
is the Sieve of Eratosthenes and has signature

primes :: Integral a = [a]

What's also quite strange is that experiment2 is about
10 times time slower than experiment1 when 
using primes (with the Eratosthenes formula) instead of [1..].

I redid the experiments with -prof and the output was quite revealing:

experiment1 (fastest):
total time  =2.64 secs   (132 ticks @ 20 ms)
total alloc = 323,356 bytes  (excludes profiling overheads)

individualinherited
COST CENTRE   entries  %time %alloc   %time %alloc

MAIN 0   0.00.0   100.0  100.0
 main1   0.00.5 0.00.5
 CAF 4   0.00.0   100.0   99.0
  primes 1   9.8   61.9 9.8   61.9
  main   0   0.0   37.190.2   37.1
   isPrime5000  90.20.090.20.0
 CAF 4   0.00.4 0.00.4


experiment2 (slowest):
total time  =6.12 secs   (306 ticks @ 20 ms)
total alloc = 350,473,356 bytes  (excludes profiling overheads)

  individualinherited
COST CENTRE entries  %time %alloc   %time %alloc

MAIN  0   0.00.0   100.0  100.0
 main 1   0.00.0 0.00.0
 CAF  4   0.00.0   100.0  100.0
  primes  1   0.00.1 0.00.1
  main0   0.00.0   100.0   99.9
   isPrime 5000 100.0   99.9   100.0   99.9
 CAF  4   0.00.0 0.00.0


Would this be only because isPrime of experiment 2 builds
this temporary list (takeWhile) all the time?

Jeroen Baekelandt






___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe