python haskell 使用对比_哪个是更具功能性的编程语言,Haskell还是Python? (Which is a more functional programming language,...

最佳答案

英文原文

While Python does indeed support some functional constructs, Haskell is a functional language. What you also need to consider, is that Haskell is also purely functional and lazy, two concepts that may be the cause of the difficulty you find in Haskell. If this is the case, read on.

What you may want to consider, if, of course, you have the time, is learning another, less complex, functional language. I found that learning a less "aggressively functional" language before moving on to Haskell is a step worth taking. You may want to consider OCaml (Objective Caml), another functional programming language, that is not pure nor lazy. Thus, some imperative programming constructs will be available to you (references, loops, mutable arrays, etc), and you won't have to cope with the monads until you actually want to.

This entirely depends on the time you are willing to spend revisiting functional programming, and on your current background in this same paradigm.

中文翻译

虽然Python确实支持一些功能构造,但Haskell 是一种功能语言。您还需要考虑的是,Haskell也是纯功能和lazy,这两个概念可能是您在Haskell中遇到困难的原因。如果是这种情况,请继续阅读。

当你有时间的时候,你可能想要考虑的是学习另一种不那么复杂的功能性语言。我发现在转向Haskell之前学习一种不那么" 积极主动" 的语言是值得采取的步骤。您可能想要考虑另一种函数式编程语言OCaml(Objective Caml),它不是纯粹的也不是懒惰的。因此,一些命令式编程结构将可供您使用(引用,循环,可变数组等),并且您不必在实际需要之前处理monad。

这完全取决于您愿意花时间重新考虑函数式编程的时间,以及您在同一范例中的当前背景。

While Python does indeed support some functional constructs, Haskell is a functional language. What you also need to consider, is that Haskell is also purely functional and lazy, two concepts that may be the cause of the difficulty you find in Haskell. If this is the case, read on.

What you may want to consider, if, of course, you have the time, is learning another, less complex, functional language. I found that learning a less "aggressively functional" language before moving on to Haskell is a step worth taking. You may want to consider OCaml (Objective Caml), another functional programming language, that is not pure nor lazy. Thus, some imperative programming constructs will be available to you (references, loops, mutable arrays, etc), and you won't have to cope with the monads until you actually want to.

This entirely depends on the time you are willing to spend revisiting functional programming, and on your current background in this same paradigm.

虽然Python确实支持一些功能构造,但Haskell 是一种功能语言。您还需要考虑的是,Haskell也是纯功能和lazy,这两个概念可能是您在Haskell中遇到困难的原因。如果是这种情况,请继续阅读。

当你有时间的时候,你可能想要考虑的是学习另一种不那么复杂的功能性语言。我发现在转向Haskell之前学习一种不那么" 积极主动" 的语言是值得采取的步骤。您可能想要考虑另一种函数式编程语言OCaml(Objective Caml),它不是纯粹的也不是懒惰的。因此,一些命令式编程结构将可供您使用(引用,循环,可变数组等),并且您不必在实际需要之前处理monad。

这完全取决于您愿意花时间重新考虑函数式编程的时间,以及您在同一范例中的当前背景。

参考答案2

Haskell is a functional programming language, whereas Python just has some features of functional programming languages. So, this is settled. Q.e.d.

Edit: What is lacking in Python, just to give one example, is the optimization of recursive function calls. This is vital in most real functional programming languages.

Googling, by the way, just produced this nice article.

参考答案3

You'll find many criticisms elsewhere about how Python programmers should not use functional features like lambda. Alex Martelli is particularly good at this. But if you approach functional programming as a Python programmer, you will not get much of a feel for why people are interested in functional programming in the first place. In particular, you will not have access to a powerful static type system and algebraic data types. These tools are definitely part of the Haskell mindset.

Functional programming is not so much a set of features a a way of thinking. To see that way of thinking in action and to start to learn it, check out the paper Why Functional Programming Matters by John Hughes. What you learn from Hughes you can easily apply in Haskell. In fact, Haskell is much more likely to force you to learn that new way of thinking. With Python you can use a few lambdas here and there and fool yourself that you're learning functional programming. You won't be.

That said, Haskell can be a lot to swallow all at once. If you're finding it difficult you might want to try Standard ML or Racket (formerly called PLT Scheme or DrScheme). Standard ML will introduce you to more new ideas, but those people don't have their act together to welcome newcomers in the way that the Racketeers or the Haskell people do.

参考答案4

This question highlights one of my pet peeves about the common understanding of functional programming. Having language features like closures and first-class functions do not make a language a functional programming language. Functional programming is as much about a specific style of programming as it is about specific language constructs. Python has closures, first-class functions, and yes, even a function called "map", but the language itself encourages a procedural, OOP, imperative style of programming; so even if you make use of the functional features, you're still programming imperatively.

As a purely functional language, Haskell basically mandates that one program in a declarative, functional style, so hands-down, Haskell is "more functional" than Python.

参考答案5

What Boldewyn said. Haskell is one of the most "hardcore" functional languages there is, insofar as there simply isn't any way to maintain mutable state.

That said, Haskell is (unsurprisingly) wildly different from all the imperative and mixed-model languages most people come in contact with, so there would be a learning curve involved in picking it up if one came from a background of, say, VB or C(++) or Java.

Python, on the other hand, features a "Functional Show and Tell" section where a handful of functional features can be test driven within an otherwise predominantly imperative environment.

Thus, if in his original question, the OP's "better" meant "more functional" or "a better citizen of functional-land" (as he has since made clearer), then Haskell "wins" hands down.

参考答案6

Haskell is an advanced purely functional programming language. An open source product of more than twenty years of cutting edge research, it allows rapid development of robust, concise, correct software.

Sarcastic translation:

"advanced" = "Not for everyone"

"purely functional" = "Definitely not for everyone"

"more than twenty years" = "And still not everyone likes it!"

"cutting edge research" = "There is a chance that you may find a practical problem which you can solve with it but we're still working on it!"

"robust, concise, correct software" = "Are you missing simple, understandable, obvious, readable? Guess why!"

Jokes aside, functional languages aren't meant for the majority and never will be. There are people who can think like a stack but I, for one, prefer that the computer tries harder to understand my gibberish.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值