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: Exposing Ratio data constructor ( Chadda? Fouch? )
2. Perfect numbers (Matthew Williams)
3. Re: Perfect numbers (wman)
4. Re: Perfect numbers (Jason Dusek)
5. Re: Perfect numbers (wman)
----------------------------------------------------------------------
Message: 1
Date: Mon, 29 Sep 2008 21:03:50 +0200
From: " Chadda? Fouch? " <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] Exposing Ratio data constructor
To: "Casey Rodarmor" <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1
2008/9/29 Casey Rodarmor <[EMAIL PROTECTED]>:
>
> invertRatio r = denominator r % numerator
Ratio is an instance of Fractional, which means :
invertRation = recip
ou
invert f = 1 / f
(probably the default definition of recip anyway).
> Is there any way to avoid this, while still letting the user benefit
> from the nice pattern matching syntax that exposing the data
> constructor allows?
To this more general question : allow the convenience of pattern
matching while keeping a datatype abstract, the latest GHC (6.10)
bring a new extension called "view pattern", it may not be ideal but
it should be pretty useful in this direction.
http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns
--
Jedaï
------------------------------
Message: 2
Date: Thu, 2 Oct 2008 05:45:01 +0100
From: "Matthew Williams" <[EMAIL PROTECTED]>
Subject: [Haskell-beginners] Perfect numbers
To: <[email protected]>
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset="us-ascii"
Hi Guys,
I'm new to Haskell and I was wondering if you can help me:
One of the first program's I tend to write when I'm looking at a new
language is a program to generate a list of perfect numbers:
--My First Perfect Number Generator
factors :: Integer -> [Integer]
factors x = [z | z <- [1..x-1], x `mod` z == 0]
is_perfect :: Integer -> Bool
is_perfect x = if sum(factors x) == x then True else False
do_perfect :: [Integer] -> [Integer]
do_perfect x = [z |z <- x, is_perfect z ]
Then to run it:
> do_perfect [1..9000]
I'm using GHC to run it. My problem / question is this: It's running
quite a lot slower than equivalent programs in erlang and python. I
suspect it's down to the way I've written it. Any thoughts (or comments
in general)
Many thanks
Matt
______________________________________________________________________
This email may contain privileged or confidential information, which should
only be used for the purpose for which it was sent by Xyratex. No further
rights or licenses are granted to use such information. If you are not the
intended recipient of this message, please notify the sender by return and
delete it. You may not use, copy, disclose or rely on the information contained
in it.
Internet email is susceptible to data corruption, interception and unauthorised
amendment for which Xyratex does not accept liability. While we have taken
reasonable precautions to ensure that this email is free of viruses, Xyratex
does not accept liability for the presence of any computer viruses in this
email, nor for any losses caused as a result of viruses.
Xyratex Technology Limited (03134912), Registered in England & Wales,
Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
The Xyratex group of companies also includes, Xyratex Ltd, registered in
Bermuda, Xyratex International Inc, registered in California, Xyratex
(Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd
registered in The People's Republic of China and Xyratex Japan Limited
registered in Japan.
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20081002/fb1929bb/attachment-0001.htm
------------------------------
Message: 3
Date: Thu, 2 Oct 2008 07:25:17 +0200
From: wman <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] Perfect numbers
To: "Matthew Williams" <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
First step would probably be using Ints instead of Integers.
On Thu, Oct 2, 2008 at 6:45 AM, Matthew Williams <
[EMAIL PROTECTED]> wrote:
> Hi Guys,
>
> I'm new to Haskell and I was wondering if you can help me:
>
> One of the first program's I tend to write when I'm looking at a new
> language is a program to generate a list of perfect numbers:
>
> --My First Perfect Number Generator
> factors :: Integer -> [Integer]
> factors x = [z | z <- [1..x-1], x `mod` z == 0]
>
> is_perfect :: Integer -> Bool
> is_perfect x = if sum(factors x) == x then True else False
>
> do_perfect :: [Integer] -> [Integer]
> do_perfect x = [z |z <- x, is_perfect z ]
>
> Then to run it:
> > do_perfect [1..9000]
>
> I'm using GHC to run it. My problem / question is this: It's running quite
> a lot slower than equivalent programs in erlang and python. I suspect it's
> down to the way I've written it. Any thoughts (or comments in general)
>
> Many thanks
>
> Matt
>
> ______________________________________________________________________
> This email may contain privileged or confidential information, which should
> only be used for the purpose for which it was sent by Xyratex. No further
> rights or licenses are granted to use such information. If you are not the
> intended recipient of this message, please notify the sender by return and
> delete it. You may not use, copy, disclose or rely on the information
> contained in it.
>
> Internet email is susceptible to data corruption, interception and
> unauthorised amendment for which Xyratex does not accept liability. While we
> have taken reasonable precautions to ensure that this email is free of
> viruses, Xyratex does not accept liability for the presence of any computer
> viruses in this email, nor for any losses caused as a result of viruses.
>
> Xyratex Technology Limited (03134912), Registered in England & Wales,
> Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>
> The Xyratex group of companies also includes, Xyratex Ltd, registered in
> Bermuda, Xyratex International Inc, registered in California, Xyratex
> (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd
> registered in The People's Republic of China and Xyratex Japan Limited
> registered in Japan.
> ______________________________________________________________________
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20081002/0734ecc1/attachment-0001.htm
------------------------------
Message: 4
Date: Wed, 1 Oct 2008 22:54:00 -0700
From: "Jason Dusek" <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] Perfect numbers
To: wman <[EMAIL PROTECTED]>
Cc: Matthew Williams <[EMAIL PROTECTED]>,
[email protected]
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset=UTF-8
On Wed, Oct 1, 2008 at 22:25, wman <[EMAIL PROTECTED]> wrote:
> First step would probably be using Ints instead of Integers.
Doesn't seem to make a real difference in GHCi.
--
_jsn
Prelude> do_perfect [1..2000] :: [Integer]
[6,28,496]
it :: [Integer]
(4.22 secs, 169352736 bytes)
Prelude> do_perfect [1..2000] :: [Int]
[6,28,496]
it :: [Int]
(4.23 secs, 153699692 bytes)
------------------------------
Message: 5
Date: Thu, 2 Oct 2008 07:54:47 +0200
From: wman <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] Perfect numbers
To: "Matthew Williams" <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
factors :: Int -> [Int]
factors x = [z | z <- [1..(x `div` 2)], x `mod` z == 0]
is_perfect :: Int -> Bool
is_perfect x = sum(factors x) == x
do_perfect :: [Int] -> [Int]
do_perfect x = [z |z <- x, is_perfect z ]
main = print $ do_perfect [1..9000]
-- compile with ghc -O2, it's more than ten times faster for me
-- althought using 1..(x `div 2) instead of 1..x-1 is a bit of cheating ;-))
On Thu, Oct 2, 2008 at 6:45 AM, Matthew Williams <
[EMAIL PROTECTED]> wrote:
> Hi Guys,
>
> I'm new to Haskell and I was wondering if you can help me:
>
> One of the first program's I tend to write when I'm looking at a new
> language is a program to generate a list of perfect numbers:
>
> --My First Perfect Number Generator
> factors :: Integer -> [Integer]
> factors x = [z | z <- [1..x-1], x `mod` z == 0]
>
> is_perfect :: Integer -> Bool
> is_perfect x = if sum(factors x) == x then True else False
>
> do_perfect :: [Integer] -> [Integer]
> do_perfect x = [z |z <- x, is_perfect z ]
>
> Then to run it:
> > do_perfect [1..9000]
>
> I'm using GHC to run it. My problem / question is this: It's running quite
> a lot slower than equivalent programs in erlang and python. I suspect it's
> down to the way I've written it. Any thoughts (or comments in general)
>
> Many thanks
>
> Matt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20081002/4b56b37f/attachment.htm
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 4, Issue 1
***************************************