Mutability in functional programming

前端 未结 4 755
猫巷女王i
猫巷女王i 2021-02-05 13:02

First I am a Haskell newbie. I\'ve read this: Immutable functional objects in highly mutable domain And my question is nearly the same -- how to efficiently write algorithms whe

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 13:15

    Creating new immutable objects isn't nearly as expense as you might think, since large amounts of structural sharing can occur because the compiler KNOWS they can't change and thus can be safely shared. That said, using highly imperative algorithms with lots of mutable state in Haskell is a bit of a code smell.

提交回复
热议问题