Mutability in functional programming

前端 未结 4 747
猫巷女王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:24

    In ML derivatives (such as OCaml, SML, F#), there are "references", which can be used as mutable variables.

    In Haskell, this isn't cleanly handled. State is simply not covered by the usual "purely functional" style. Pure FP languages deal with "eternal truths", and are thus not very suitable for working with "ephemeral truths" (although it can be done, definitely).

    However, yes, sometimes we need mutable state. A language such as ATS incorporates linear types for handling destructive updates and safe resource manipulation.

提交回复
热议问题