I want to find all prime factors of a given number using only list comprehension method and/or . (function composition operator) in Haskell. I specifically want to avoid a recursive solution.
For example, pfactors 120 must produce [2,2,2,3,5] output.
I tried:
pfactors n = [p | p <- [2..n], n `mod` p == 0, [d | d <- [1..p], p `mod` d == 0] == [1,p]]
But when I call pfactors 120, the result is [2,3,5], not all prime factors.