Why is Haskell (sometimes) referred to as “Best Imperative Language”?

后端 未结 3 670
小蘑菇
小蘑菇 2020-11-30 18:28

(I hope this question is on-topic -- I tried searching for an answer but didn\'t find a definitive answer. If this happens to be off-topic or already answered, please mo

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 19:09

    In addition to what other's have already mentioned, having side-effecting actions be first-class is sometimes useful. Here's a silly example to show the idea:

    f = sequence_ (reverse [print 1, print 2, print 3])
    

    This example shows how you can build up computations with side-effects (in this example print) and then put the in data structures or manipulate them in other ways, before actually executing them.

提交回复
热议问题