
I wrote the following program a while ago :-
import List
sumFacDigits 0 = 0 sumFacDigits n = product [1 .. mod n 10] + sumFacDigits (div n 10)
lenFacCycle n = length (nub (take 60 (iterate sumFacDigits n)))
main = do print ( sum [ 1 | n <- [1 .. ((10^6) - 1)], lenFacCycle n == 60 ] ) It compiles and runs fine.
To get rid of the brackets, I used the function composition operators . and $. (Incidentally why does nobody tell you that you can use . provided the last composition operator is $?) It now reads:-
import List
sumFacDigits 0 = 0 sumFacDigits n = product [1 .. mod n 10] + sumFacDigits n `div` 10
lenFacCycle n = length . nub . take 60 $ iterate sumFacDigits n
main = do print ( sum [ 1 | n <- [1 .. ((10^6) - 1)], lenFacCycle n == 60 ] ) This compiles. When I run it however, it exits with the stack exceeded message.
Why? Are the function composition operators more than syntactic sugar for the brackets?