Are some data structures more suitable for functional programming than others?

后端 未结 9 703
灰色年华
灰色年华 2021-01-31 19:23

In Real World Haskell, there is a section titled \"Life without arrays or hash tables\" where the authors suggest that list and trees are preferred in functional programming, w

9条回答
  •  时光取名叫无心
    2021-01-31 19:36

    • Are there really significantly different usage patterns for data structures between functional and imperative programming?

    Big, gigantic, night and day — largely because side-effects are not tolerated in functional programming.

    • If so, is this a problem?

    The problem is for the imperative paradigms that will be unable to retain efficiency as parallelization becomes more necessary — the only way out for these languages will be to get rid of side-effects but then they will become broken functional languages - but then, why should I bother with them when there are some pretty good, working functional languages. Also, the semantics of functional languages is easier to control hence, functional programs can be proved correct whereas their C++ counterparts cannot (yet, anyway). Hence, many formal verification tools are based on functional languages — for example, ACL2 is based on common lisp and Cryptol is based on Haskell. Since Formal Verification is the wave of the future functional languages can better integrate with those tools. In short, say bye-bye to C,C++ and such — good ridence! Someone should have taken a 30 ought 6 to them a long time ago.

    • What if you really do need a hash table for some application? Do you simply swallow the extra expense incurred for modifications?

    The wave of the future is this: you write a functional programming with specifying a hash table - the language you use is cryptol. When you are done and have proven that your program works you press a button and out pops an efficient version that uses a hash table if it has been decided that is the best thing to use.

提交回复
热议问题