Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

haskell - Haskell入门(Getting started with Haskell)

For a few days I've tried to wrap my head around the functional programming paradigm in Haskell.

(几天后,我试图围绕Haskell中的函数式编程范例。)

I've done this by reading tutorials and watching screencasts, but nothing really seems to stick.

(我通过阅读教程和观看截屏视频来完成这项工作,但似乎并没有真正坚持下去。)

Now, in learning various imperative/OO languages (like C, Java, PHP), exercises have been a good way for me to go.

(现在,在学习各种命令式/ OO语言(如C,Java,PHP)时,练习对我来说是个好方法。)

But since I don't really know what Haskell is capable of and because there are many new concepts to utilize, I haven't known where to start.

(但由于我不知道Haskell能够做什么,并且因为有许多新概念可供使用,我还不知道从哪里开始。)

So, how did you learn Haskell?

(那么,你是如何学习Haskell的?)

What made you really "break the ice"?

(是什么让你真正“打破僵局”?)

Also, any good ideas for beginning exercises?

(还有开始练习的好主意吗?)

  ask by community wiki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm going to order this guide by the level of skill you have in Haskell, going from an absolute beginner right up to an expert.

(我将按照您在Haskell中的技能水平订购本指南,从绝对的初学者到专家。)

Note that this process will take many months (years?), so it is rather long.

(请注意,此过程需要几个月(几年?),所以它相当长。)

Absolute Beginner

(绝对的菜鸟)

Firstly, Haskell is capable of anything, with enough skill.

(首先,Haskell能够胜任任何事情,具备足够的技能。)

It is very fast (behind only C and C++ in my experience), and can be used for anything from simulations to servers, guis and web applications.

(它非常快(在我的经验中只支持C和C ++),可用于从模拟到服务器,guis和Web应用程序的任何事情。)

However there are some problems that are easier to write for a beginner in Haskell than others.

(但是,对于Haskell中的初学者来说,有些问题比其他问题更容易。)

Mathematical problems and list process programs are good candidates for this, as they only require the most basic of Haskell knowledge to be able to write.

(数学问题和列表处理程序是很好的选择,因为它们只需要最基本的Haskell知识就可以编写。)

Firstly, some good guides to learning the very basics of Haskell are the happy learn haskell tutorial and the first 6 chapters of learn you a haskell .

(首先,学习Haskell基础知识的一些很好的指南是快乐学习haskell教程和前6章学习你的haskell 。)

While reading these, it is a very good idea to also be solving simple problems with what you know.

(在阅读这些内容时,同样用您所知道的解决简单问题也是一个非常好的主意。)

Another two good resources are Haskell Programming from first principles , and Programming in Haskell .

(另外两个好的资源是来自第一原理的Haskell编程Haskell中的编程 。)

They both come with exercises for each chapter, so you have small simple problems matching what you learned on the last few pages.

(他们都为每一章都附带练习,所以你有一些小问题与你在最后几页学到的东西相匹配。)

A good list of problems to try is the haskell 99 problems page .

(要尝试的一个很好的问题列表是haskell 99问题页面 。)

These start off very basic, and get more difficult as you go on.

(这些开始非常基础,并且随着你的继续变得更加困难。)

It is very good practice doing a lot of those, as they let you practice your skills in recursion and higher order functions.

(这很好的做法很多,因为它们让你练习递归和高阶函数的技能。)

I would recommend skipping any problems that require randomness as that is a bit more difficult in Haskell.

(我建议跳过任何需要随机性的问题,因为在Haskell中这有点困难。)

Check this SO question in case you want to test your solutions with QuickCheck (see Intermediate below).

(如果您想使用QuickCheck测试解决方案,请查看此问题 (请参阅下面的中间版 )。)

Once you have done a few of those, you could move on to doing a few of the Project Euler problems.

(一旦你完成了其中的一些,你就可以继续做一些Project Euler问题。)

These are sorted by how many people have completed them, which is a fairly good indication of difficulty.

(这些是根据完成它们的人数排序的,这是一个相当好的困难迹象。)

These test your logic and Haskell more than the previous problems, but you should still be able to do the first few.

(这些测试你的逻辑和Haskell比以前的问题更多,但你仍然应该能够做到前几个。)

A big advantage Haskell has with these problems is Integers aren't limited in size.

(Haskell对这些问题的一个很大的优势是整数的大小不受限制。)

To complete some of these problems, it will be useful to have read chapters 7 and 8 of learn you a Haskell as well.

(要完成其中的一些问题,阅读第7章和第8章将了解Haskell是很有用的。)

Beginner

(初学者)

After that you should have a fairly good handle on recursion and higher order functions, so it would be a good time to start doing some more real world problems.

(在那之后你应该对递归和更高阶函数有一个相当好的处理,所以这是开始做一些更真实的世界问题的好时机。)

A very good place to start is Real World Haskell (online book, you can also purchase a hard copy).

(一个非常好的起点是Real World Haskell (在线书籍,你也可以购买一份硬拷贝)。)

I found the first few chapters introduced too much too quickly for someone who has never done functional programming/used recursion before.

(我发现前几章对于从未完成过函数式编程/使用递归的人来说太快了。)

However with the practice you would have had from doing the previous problems you should find it perfectly understandable.

(然而,通过练习以前遇到的问题,您应该会发现它完全可以理解。)

Working through the problems in the book is a great way of learning how to manage abstractions and building reusable components in Haskell.

(解决本书中的问题是学习如何在Haskell中管理抽象和构建可重用组件的好方法。)

This is vital for people used to object-orientated (oo) programming, as the normal oo abstraction methods (oo classes) don't appear in Haskell (Haskell has type classes, but they are very different to oo classes, more like oo interfaces).

(这对于习惯于面向对象(oo)编程的人来说至关重要,因为正常的oo抽象方法(oo类)没有出现在Haskell中(Haskell有类型类,但它们与oo类非常不同,更像是oo接口)。)

I don't think it is a good idea to skip chapters, as each introduces a lot new ideas that are used in later chapters.

(我不认为跳过章节是个好主意,因为每个章节都会引入很多新的想法,这些想法将在后面的章节中使用。)

After a while you will get to chapter 14, the dreaded monads chapter (dum dum dummmm).

(过了一会儿,你将进入第14章,可怕的monads章节(dum dum dummmm)。)

Almost everyone who learns Haskell has trouble understanding monads, due to how abstract the concept is.

(几乎每个学习Haskell的人都难以理解monad,因为这个概念有多抽象。)

I can't think of any concept in another language that is as abstract as monads are in functional programming.

(我想不出另一种语言中的任何概念,就像monad在函数式编程中一样抽象。)

Monads allows many ideas (such as IO operations, computations that might fail, parsing,...) to be unified under one idea.

(Monads允许在一个想法下统一许多想法(例如IO操作,可能失败的计算,解析......)。)

So don't feel discouraged if after reading the monads chapter you don't really understand them.

(因此,如果在阅读了monad章节后你并不真正理解它们,请不要气馁。)

I found it useful to read many different explanations of monads;

(我发现阅读monad的许多不同解释很有用;)

each one gives a new perspective on the problem.

(每个人都对这个问题提出了新的看法。)

Here is a very good list of monad tutorials .

(这是一个非常好的monad教程列表 。)

I highly recommend the All About Monads , but the others are also good.

(我强烈推荐All About Monads ,但其他人也很好。)

Also, it takes a while for the concepts to truly sink in. This comes through use, but also through time.

(此外,概念需要一段时间才能真正沉入其中。这是通过使用,也是通过时间来实现的。)

I find that sometimes sleeping on a problem helps more than anything else!

(我发现有时睡在一个问题上比其他任何事情更有帮助!)

Eventually, the idea will click, and you will wonder why you struggled to understand a concept that in reality is incredibly simple.

(最终,这个想法会点击,你会想知道为什么你很难理解一个实际上非常简单的概念。)

It is awesome when this happens, and when it does, you might find Haskell to be your favorite imperative programming language :)

(当这种情况发生时很棒,当它发生时,你可能会发现Haskell是你最喜欢的命令式编程语言:))

To make sure that you are understanding Haskell type system perfectly, you should try to solve 20 intermediate haskell exercises .

(为了确保您完全理解Haskell类型系统,您应该尝试解决20个中间haskell练习 。)

Those exercises using fun names of functions like "furry" and "banana" and helps you to have a good understanding of some basic functional programming concepts if you don't have them already.

(这些练习使用有趣的名称,如“毛茸茸”和“香蕉”,并帮助您很好地理解一些基本的函数式编程概念,如果你还没有它们。)

Nice way to spend your evening with a bunch of papers covered with arrows, unicorns, sausages and furry bananas.

(用一堆纸,箭头,独角兽,香肠和毛茸茸的香蕉来度过你的夜晚的好方法。)

Intermediate

(中间)

Once you understand Monads, I think you have made the transition from a beginner Haskell programmer to an intermediate haskeller.

(一旦你理解了Monads,我认为你已经从初学者Haskell程序员转变为中级haskeller。)

So where to go from here?

(那么从哪里开始呢?)

The first thing I would recommend (if you haven't already learnt them from learning monads) is the various types of monads, such as Reader, Writer and State.

(我建议的第一件事(如果你还没有从学习monad中学到它们)是各种类型的monad,例如Reader,Writer和State。)

Again, Real world Haskell and All about monads gives great coverage of this.

(再一次,真实世界的Haskell和All about monads给出了很好的报道。)

To complete your monad training learning about monad transformers is a must.

(要完成你的monad训练,学习monad变形金刚是必须的。)

These let you combine different types of Monads (such as a Reader and State monad) into one.

(这些允许您将不同类型的Monad(例如Reader和State monad)组合成一个。)

This may seem useless to begin with, but after using them for a while you will wonder how you lived without them.

(这可能看起来没用,但是在


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...