This is a strictness problem. The call to generate
in
| otherwise = itbl (i + 1) $ V.generate (k + 1) gen
does not actually force the vector into memory.
You can either import Control.DeepSeq
and replace $
by deeply strict application $!!
:
| otherwise = itbl (i + 1) $!! V.generate (k + 1) gen
or you can use an unboxed vector (which is probably faster) instead, by changing the import statements to
import Data.Vector.Unboxed (Vector, (!))
import qualified Data.Vector.Unboxed as V
(and leaving everything else as in your original program).