
Hi, I was hoping to get a code critique from some experienced Haskell people. I put my code up in this blog post: http://learnmeahaskell.blogspot.com/2011/03/playing-around-with-quickcheck.h... . thanks Lee

Am 31.03.2011 17:55, schrieb blackcat@pro-ns.net:
Hi,
I was hoping to get a code critique from some experienced Haskell people. I put my code up in this blog post: http://learnmeahaskell.blogspot.com/2011/03/playing-around-with-quickcheck.h... .
Without trying to understand your code I'm disturbed by a) duplicate code in factors' namely x `mod` y == 0 && y*y ... factors' x (y+1) b) "sort $ nub" (even twice) first sort and then removing duplicates can be more efficient, I would suggest: "Data.Set.toList . Data.Set.fromList" c) using (head xs) and (tail xs) in "check" (without "null xs" test) looks suspicious. Use pattern matching on xs (instead of on number y)! HTH Christian
thanks Lee

Thanks for the comments, Christian. Looking at the structure of the code overall, I should just be using a set for the set of factors, not a list. That's the fundamental problem there. I'm just so focused on list processing in Haskell that I didn't take the time to examine if it was appropriate here.
b) "sort $ nub" (even twice)
first sort and then removing duplicates can be more efficient, I would suggest: "Data.Set.toList . Data.Set.fromList"
participants (2)
-
blackcat@pro-ns.net
-
Christian Maeder