学习 Haskell 是为了学习 Scala
我读过一些问题,例如 Scala vs Haskell,讨论两种语言的优点或学习哪种语言,但我已经知道我想学习 Scala。我在大学时是一名Java程序员,现在主要使用PHP。
我想学习 Scala,因为它看起来像是个人项目中 Java 的改进,而且我还想学习一门函数式语言来提高我作为程序员的知识。
我想知道学习 Haskell 作为函数式编程的入门是否是一个好主意,因为它是纯粹的函数式编程,所以我会正确地学习它,而不是在不知道为什么的情况下随意使用 Scala 中的一些函数式编程?
我还想将 Haskell 用于个人项目等,因为它看起来很棒,但我并没有真正看到它在现实世界中的许多应用,似乎更多用于学术内容,因此想学习它以获得功能理解,然后继续前进到斯卡拉。
I've read a few questions such as Scala vs Haskell discussing the merits of both languages or which to learn, but I already know that I'd like to learn Scala. I was a Java programmer at uni and now mainly use PHP.
I want to learn Scala as it looks like an improvement on Java for personal projects and I'd also like to learn a functional language to improve my knowledge as a programmer.
I am wondering if it would be a good idea to learn Haskell as an introduction to functional programming as it is purely functional so I'd properly learn it rather than haphazard using bits of functional in Scala without knowing why?
I'd also like to use Haskell for personal projects etc as it looks great, but I don't really see many real world applications of it, seems more used for academic stuff hence wanting to learn it to get the functional understanding then move on to Scala.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
作为一个来自 Java 的人,对于 Scala 来说是 Haskell 的入门药物,我碰巧认为这是一个好主意(先学习 Haskell)!
从概念上讲,Haskell 是一种比 Scala 简单得多的语言,如果您的目标是学习如何进行函数式编程,那么从 Haskell 开始,您就会情不自禁地这样做。根据设计,Scala 支持一种“遗留模式”的编码,在这种模式下,如果您不愿意,实际上不必改变太多 Java(或 PHP)习惯。我认为这是一个战略决策——而且是一个好的决策!——旨在提高顽固的 Java 坚定拥护者的采用率。
但那不是你!您实际上对学习新东西感兴趣...那么为什么不全力以赴呢?在纯粹的环境中学习函数式编程,没有混乱和回归旧习惯的诱惑,将使你大脑中的概念具体化。
然后一定要返回 Scala 并了解它与 Haskell 有何不同;它在某些方面较弱,而在另一些方面则较强,但你将有一个更好的基础来欣赏这些差异。
Speaking as someone who came from Java, and for whom Scala was a gateway drug to Haskell, I happen to think this is a great idea (learn Haskell first)!
Haskell is conceptually a much simpler language than Scala, and if your goal is to learn how to program functionally, you can't help but do so if you start with Haskell. By design, Scala supports a kind of "legacy mode" of coding in which you don't really have to change your Java (or PHP) habits too much if you don't want to. I think this is a strategic decision--and a good one!--meant to increase adoption amongst crusty Java stalwarts.
But that's not you! You're actually interested in learning something new... so why not go all-out? Learning functional programming in a pure setting, without the clutter and the temptation to regress into old habits, will crystallize the concepts in your brain.
Then by all means return to Scala and learn how it differs from Haskell; it is both weaker in some respects and stronger in others, but you will then be on a much better foundation to appreciate these differences.
我是从 Java 背景来到 Scala 的。最初,我只是将 Scala 视为更好的 Java。随着时间的推移,我开始在 Scala 中使用越来越多的函数式概念。最终我觉得我需要对函数式编程有更纯粹的理解。正是在这个时候,我离开并学习了 Haskell。
当我回到 Scala 时,我发现使用函数式风格要容易得多,而且我之前遇到的一些概念也变得更有意义。
你不必学习 Haskell 才能成为一名优秀的 Scala 开发人员,但我认为一旦你在 Scala 中达到一定的水平,对函数式编程概念有更深入的了解确实会有所帮助。
I came to Scala from a Java background. Initially I just focused on Scala as a better Java. As time went on I started to use more and more functional concepts in Scala. Eventually I reached a point where I felt I needed a purer understanding of functional programming. It was at this point that I went away and learnt Haskell.
When I cam back to Scala I found it much easier to use a functional style and some of the the concepts I struggled with previously made much more sense.
You don't have to learn Haskell to become a good Scala developers, but I think once you get to a certain level in Scala that having a deeper understanding of functional programming concepts really helps.
我不会那样做。如果您直接进入 Scala(您的最终目标),您可以节省时间。无论如何,您都会学习函数式编程,但由于 Scala“不太纯粹”,您将能够开始使用一些类似 Java 的结构在 Scala 中编写程序,这将使转换更简单。
即使您进入 Haskell,您的第一个程序的“功能质量”也会低于后来的程序,因为只有实践才能改善这一点。开始使用 Scala 时,您的第一个程序将像 Java 或 PHP 中的第一个程序一样“质量较低”,但通过练习,您会有所提高。把时间花在不相关的任务上,希望它们能有所帮助,这可能会导致你浪费时间。
专注于你的目标。如果那是 Scala,那就去吧。
更新:我相信这个 可能与问题相关。它提出了生产力(交付软件)与寻求“纯知识”的观点。
I wouldn't do that. If you go straight to Scala (your final aim) you save time. You'll learn functional programming anyway, but as Scala is "less pure" you'll be able to start writing programs in Scala usign some Java-like constructs, which will make the transition simpler.
Even if you go into Haskell, your first programs will be of less "functional quality" than later ones, as only practice improves that. Starting Scala your first programs will be of "less quality" as your first programs in Java or PHP were, but with practice you'll improve. Spending time in unrelated tasks hoping they MAY help, it can result in you wasting that time.
Focus on your aim. If that's Scala, go for it.
UPDATE: I believe this may be relevant to the question. It raises a point on productivity (deliver software) vs seeking "pure knowledge".
在没有先玩过任何纯函数式编程语言的情况下直接从 Scala 开始的风险是,您可能会过于频繁地被过程式解决方案所吸引。
不过,我不会尝试将 Haskell 作为函数式编程的入门:并不是说它特别难 - 它的语法非常简洁 - 但它绝对非常奇特(即使在函数式编程的特殊世界中),我认为你应该尝试使用您可以更轻松地移植到 Scala 的语言,例如 Racket 或普通的 Scheme。
为了更好地理解我的意思,请查看 Haskell、Scala 和 Scheme 中的列表推导式。
The risk of starting directly from Scala, without having played any purely functional programming language first, is that you'll probably be drawn to the procedural solutions a bit too often.
I wouldn't try Haskell as an intro to functional programming, though: not that it's particularly hard - its syntax is amazingly terse - but it's definitely very peculiar (even in the peculiar world of functional programming) and I think you should try with a language you can port more easily to Scala, like Racket or plain Scheme.
To better understand what I mean, look at list comprehensions in Haskell, Scala and Scheme.
我先学了 Haskell,然后学了 Scala,从未后悔过。如果你先学习 Haskell,你将会对 FP 有更深入的了解。您对 FP 背后的概念及其重要性的理解将会深入人心。Scala 的大部分内容都取自 Haskell(恕我直言)。当你有 Haskell 背景时,它会更有意义。不要回避!你的努力将会得到回报。
I learned Haskell first and then Scala and never regretted. You will gain a much deeper appreciation of FP if you learn Haskell first. Your understanding of the concepts behind FP and why they are important will be seared in. Much of Scala is taken from Haskell (IMHO). It will make more sense when you have the Haskell background. Don't shy away! Your efforts will be rewarded.
对我来说,我想学习Scala和函数式编程;因此,简单地说,我正在学习 Scala。我的学习材料是Programming Scala。在我读完关于 syntx 等内容的早期章节后,我跳过了涉及 OO 内容的章节,跳到了涵盖函数式编程内容的第 8 章。在那里我让自己与 FP 作斗争。
我读了 这段 scala 代码,它是用 FP 方式编写的,并分析了 它。您希望学习 Scala 是为了“...个人项目中对 Java 的改进”。和 Haskell 进行 FP 介绍。因此,看起来首先,您希望提高 Java 项目的生产力,然后将 FP 作为副作用。为了提高工作效率,您必须掌握语言。有很多东西需要学习和掌握这门语言,掌握这门语言的唯一方法就是你必须用该语言编写代码。当你学习/使用 Scala 时,即使你愿意,你也无法避免 FP。我一直在阅读 Scala 博客(还有这本书),当涉及到 FP 概念时,作者总是不遗余力地进行解释。走Scala路线也不用担心抓不住FP。是的,您可以从 Haskell 中汲取灵感,例如这个 当你学习 Scala 时。或者正如上面 Chris Turner 所指出的,当您已经能够高效地使用 Scala 时,您可以深入研究更多 FP。
你想去A点,为什么不直接去A点呢?如果您经过 B 点(Haskell)的路线,您将不得不推迟您的生产力,如 Pere Villega 提到的。
For me, I want to learn Scala and functional programming; and, thus simply, I am learning Scala. My study material is Programming Scala. After I have read the early chapter on syntx and stuff, I have skipped chapter covering OO stuff and jumped to Chapter 8 which cover the functional programming stuff. There I let myself struggle with FP.
I read this scala code, which is written in FP way and analyze it. You want to learn Scala for "...an improvement on Java for personal projects." and Haskell for FP intro. So, it seems that first of all, you want to be productive with your java project and then grasp FP as a side effect. To be productive, you have to master the language. There are much to learn and master the language and the only way to master the language is that you have to write the code in that language. As you learn/use Scala, you can't avoid FP out right even if you want to. I have been reading the Scala blogs(the book too) and the authors always go out of their way to do explanation when it comes to FP concept. You don't have to worry about not grasping FP by going Scala route. Yes, you can draw inspiration from Haskell like this when you are learning Scala. Or as Chris Turner above have pointed out, you can delve into more FP when you are already productive with Scala.
You wanna go to point A, why not go to point A directly? If you go via the route of point B (Haskell), you will have to postpone your productivity as Pere Villega mentioned.