4 ms·
If you use the ST monad instead of State, you get actual mutable variables. STArray lets you write typical imperative algorithms that work with mutable arrays,
by spion 11y ago
If you use the ST monad instead of State, you get actual mutable variables. STArray lets you write typical imperative algorithms that work with mutable arrays, like sieve of Eratosthenes or dynamic programming.
Imperative sieve of Eratosthenes:
https://gist.github.com/rik0/1171446#file-erat1-hs https://gist.github.com/rik0/1171446#file-erat1-hs
- eru 11y agoYes. Though sieve of Eratosthenes really cries out for a sort-of-lazy infinite array.