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