[SOLVED] [HASKELL] Style advice/guidelines for code snippet
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[HASKELL] Style advice/guidelines for code snippet
I have the following haskell code, but I don't feel that it's really in keeping with haskell's style:
Code:
import Data.List (nub)
main :: IO ()
main = do
input <- getLine
let number = read input :: Integer
let factors = factorise number 2
let unique_factors = nub factors
let answer = list_product unique_factors
print answer
list_product :: [Integer] -> Integer
list_product [x] = x
list_product (x:s) = x * list_product s
factorise :: Integer -> Integer -> [Integer]
factorise n prime
| prime > n = []
| (mod n prime == 0) = prime : factorise (div n prime) prime
| otherwise = factorise n (prime+1)
Specifically, I'm worried by the high number of 'let' statements I have - but any more general comments on the code would be appreciated as well.
The code prints out the product of the unique factors of a number.
Thank you very much my brain's far too used to imperative programming. I might give up and learn LISP before I approach Haskell...
I'll mark it as SOLVED, as there doesn't seem to be a great many haskell users "out there", but if anyone does have any further comments, I would be interested to hear them!
Thank you very much my brain's far too used to imperative programming. I might give up and learn LISP before I approach Haskell...
Well, when I once started (mh, I tried to start) with functional programming I took a look at Haskell, but then moved to Lisp. I'm still learning Lisp. But I have great difficulties to learn the "functional thinking".
I would recommend to read the newsgroup comp.lang.lisp
There are many books about Common-Lisp, many of them also online available, for example Peter Seibel's "Practical Common Lisp" http://www.gigamonkeys.com/book/
If you're familiar with Perl you may also take a look at "Higher Order Perl" http://hop.perl.plover.com/ which is also available as PDF for free download.
Markus
Last edited by markush; 06-05-2012 at 04:39 PM.
Reason: typo
Working through this one now... Thanks for the suggestion, it's just the kind of thing I wanted for Haskell, something that was a bit more real-world-example-based.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.