Remix.run Logo
▲ seeknotfind a day ago

No, they don't have this issue. Space and time complexity apply to functional programming exactly the same as normal programming.

▲tliltocatl 21 hours ago | parent [-]

Then why does Haskell needs ST monad?

▲seeknotfind 12 hours ago | parent [-]

The short answer is because the runtime is not clever enough. The ability to do asymptotic complexity analysis and specific complexity classes are mathematical properties of code, with properties you can study such as what reductions are possible between algorithms or methods of computation. None of these have to do with runtime performance gains for specific algorithms, which is what ST monad gives you. On von neumonn architecture computers, ST monad is just more performant and convenient than writing the same code with the State monad equivalent. The asymptotic complexity can be studied as the same, perhaps within a reduction factor on any model of computation.