Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Int V.S. Word32 (Daniel Fischer)
   2.  Need advice on R vs Haskell (haskell heath)
   3. Re:  Need advice on R vs Haskell (haskell heath)
   4. Re:  Int V.S. Word32 (Haisheng Wu)


----------------------------------------------------------------------

Message: 1
Date: Sat, 19 Nov 2011 15:49:15 +0100
From: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] Int V.S. Word32
To: beginners@haskell.org
Message-ID: <201111191549.15888.daniel.is.fisc...@googlemail.com>
Content-Type: Text/Plain;  charset="utf-8"

On Saturday 19 November 2011, 09:09:50, Haisheng Wu wrote:
> Hello,
>   I got great performance difference for the following code if I used
> type `Int` rather than `Data.Word.Word32`.
>   Anyone can help to explain why such difference?

Short answer: GHC optimises Int calculations far better than Word32 
calculations, rather, it optimises more calculations for Int than for 
Word32.  It also optimises more calculations for Word than for Word32, but 
not as many as for Int.

The reason is that Int (and Word) are (at least expected to be) far more 
often used, so the effort has gone to these types primarily. Work is being 
done to get the fixed-width types on par, but it's not around the corner 
yet.

You can try using Word instead of Word32, that's likely to be faster.

But

>   Thanks a lot.
> 
> -Simon
> 
> module Main where
> import Data.Word
> 
> main :: IO ()
> main = print $ p14
> 
> p14 = maximum [ (startChain n 0, n) | n <- [2..1000000] ]

You get overflow using 32-bit types here.

> 
> startChain :: Word32 -> Int -> Int
> startChain 1 count    = count + 1
> startChain n count    = startChain (intTransform n) (count+1)
> 
> intTransform :: Word32 -> Word32
> intTransform n
> 
>   | even n         = n `div` 2
>   | otherwise      = 3 * n + 1




------------------------------

Message: 2
Date: Sat, 19 Nov 2011 23:52:31 -0600
From: haskell heath <haskell.he...@gmail.com>
Subject: [Haskell-beginners] Need advice on R vs Haskell
To: beginners@haskell.org
Message-ID:
        <CAEcbTvvJbTz7_tKVMqJAWhB9y_oqZ=Vx1OoXYCtMmJKVpm5=p...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I'm new to Haskell and I can't really call myself a decent programmer in
any other language. Do you think it's wrong to think that I can contribute
to the statistics library? I can't decide if I'm being pragmatic for me to
learn Haskell and contribute to the statistics library in hopes of being as
productive as I would be in learning R. I'm wanting to write a scraper and
analyze that data, and I figure this is what the statistics module can be
used for. The other alternative to Haskell and R, is to use something like
node.js for scraping, js's regex for filtering, and analyzing the resulting
data with RPy.

Here's a brief overview of my programming exp:
Python:
- How to Think Like a Computer Scientist using Python
- official tutorial
- official reference material
- a few project euler problems

Javascript
- all of the Mozilla docs

Haskell
- started with the RWH, switched to 98' Report, switched over to Yet
Another Haskell Tutorial, switched to Gentle Intro, and finally switched to
Learn You a Haskell and I'm on the seventh chapter now. I'm considering
switching yet again to A Gentle Intro, because it's been months now, and I
just want to finish one of these, and that seems to be quickest route.

Other
- I have briefly learned about C and C++, I start an intro to C++
programming next semester.

Thank you for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111119/bf91ecf0/attachment-0001.htm>

------------------------------

Message: 3
Date: Sat, 19 Nov 2011 23:57:42 -0600
From: haskell heath <haskell.he...@gmail.com>
Subject: Re: [Haskell-beginners] Need advice on R vs Haskell
To: beginners@haskell.org
Message-ID:
        <caecbtvv8k1u9xjkyxqybtykszj88qy-rbfggcyp0shah+g2...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I should also mention I've been through node.js's tutorials, and I've
briefly dabbled in Ruby. Is it far-fetched to think I can be just as
productive in Haskell as opposed to using stuff I already know? Just trying
to decide if it's worth continuing my learning experience. One alternative
I've considered is to take it slow with Haskell, and use it more for
educational purposes for now, and use it when I feel comfortable. Read
through one section of LYAH/week, one section of the R tutorial/day, and
work on one project euler problem each week.

Then again if it's just for educational purposes, I could even throw in the
SICP videos when, but I'm not sure how practical that is either.

On Sat, Nov 19, 2011 at 11:52 PM, haskell heath <haskell.he...@gmail.com>wrote:

> I'm new to Haskell and I can't really call myself a decent programmer in
> any other language. Do you think it's wrong to think that I can contribute
> to the statistics library? I can't decide if I'm being pragmatic for me to
> learn Haskell and contribute to the statistics library in hopes of being as
> productive as I would be in learning R. I'm wanting to write a scraper and
> analyze that data, and I figure this is what the statistics module can be
> used for. The other alternative to Haskell and R, is to use something like
> node.js for scraping, js's regex for filtering, and analyzing the resulting
> data with RPy.
>
> Here's a brief overview of my programming exp:
> Python:
> - How to Think Like a Computer Scientist using Python
> - official tutorial
> - official reference material
> - a few project euler problems
>
> Javascript
> - all of the Mozilla docs
>
> Haskell
> - started with the RWH, switched to 98' Report, switched over to Yet
> Another Haskell Tutorial, switched to Gentle Intro, and finally switched to
> Learn You a Haskell and I'm on the seventh chapter now. I'm considering
> switching yet again to A Gentle Intro, because it's been months now, and I
> just want to finish one of these, and that seems to be quickest route.
>
> Other
> - I have briefly learned about C and C++, I start an intro to C++
> programming next semester.
>
> Thank you for your help.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111119/ea4635d9/attachment-0001.htm>

------------------------------

Message: 4
Date: Sun, 20 Nov 2011 14:50:09 +0800
From: Haisheng Wu <fre...@gmail.com>
Subject: Re: [Haskell-beginners] Int V.S. Word32
To: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Cc: beginners@haskell.org, haskell-c...@haskell.org
Message-ID:
        <cafj8lzdxo_cxt4gypdetzgdndh2likncu-uyiju7ohqlljq...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hmm... I think I made a little confusion so I put my finding here:
http://haisgwu.info/posts/2011-11-20-euler-problem-14.html

I do got stack overflow thus need several compile opts to fix it.
Not sure if it is what you mean by "You get overflow using 32-bit types
here."

-Haisheng


On Sat, Nov 19, 2011 at 10:49 PM, Daniel Fischer <
daniel.is.fisc...@googlemail.com> wrote:

> On Saturday 19 November 2011, 09:09:50, Haisheng Wu wrote:
> > Hello,
> >   I got great performance difference for the following code if I used
> > type `Int` rather than `Data.Word.Word32`.
> >   Anyone can help to explain why such difference?
>
> Short answer: GHC optimises Int calculations far better than Word32
> calculations, rather, it optimises more calculations for Int than for
> Word32.  It also optimises more calculations for Word than for Word32, but
> not as many as for Int.
>
> The reason is that Int (and Word) are (at least expected to be) far more
> often used, so the effort has gone to these types primarily. Work is being
> done to get the fixed-width types on par, but it's not around the corner
> yet.
>
> You can try using Word instead of Word32, that's likely to be faster.
>
> But
>
> >   Thanks a lot.
> >
> > -Simon
> >
> > module Main where
> > import Data.Word
> >
> > main :: IO ()
> > main = print $ p14
> >
> > p14 = maximum [ (startChain n 0, n) | n <- [2..1000000] ]
>
> You get overflow using 32-bit types here.
>
> >
> > startChain :: Word32 -> Int -> Int
> > startChain 1 count    = count + 1
> > startChain n count    = startChain (intTransform n) (count+1)
> >
> > intTransform :: Word32 -> Word32
> > intTransform n
> >
> >   | even n         = n `div` 2
> >   | otherwise      = 3 * n + 1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111120/deaebfba/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 41, Issue 25
*****************************************

Reply via email to