According to the book this is how its done, but I am not able to get this to work. It gives me an error Not in scope: ‘ld’. I’m guessing I should be importing some package but not sure which one. Also the book uses GS module at the prompt but I’m using WinGHCi that has Prelude. What am I missing here?
factors :: Int -> [Int]
factors n | n < 1 = error "not positive"
| n == 1 = []
| otherwise = p : factors (div n p)
where p = ld n
I guess this can also be done using map and filter functions? How?
I suppose the aim of the assignment is to teach you about list comprehensions,
filterand similar constructs, and not to have you write functions that test for primality or create the list of divisors in any sensible way. Therefore what you need is a predicatedivides,Then you use that predicate for the argument to
filteror in a list comprehension to find the list of divisors, and use thedivisorsfunction for yourisPrimetest.