I have this code:
divisors n = 1:[y|y<-[2..(n `div` 2)], n `mod` y == 0]
writeList l = do print "Start"
print l
Then, i want to call the function with strict argument; i tried:
writeList $! (divisors 12345678)
and
(divisors 12345678) \`seq\` (writeList (divisors 12345678))
But it does not behave as if it has strict argument: i.e. after the "Start" I have to wait for the evaluation of (divisors 12345678)
What am I missing?
seq
(or $!
) evalueates only for first head normal form, a (:)
constructor in your case, you can use deepseq(or $!!) for evaluating to normal form.