现实世界的 Haskell 编程 [英] Real world Haskell programming

查看:36
本文介绍了现实世界的 Haskell 编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年来一直是一名命令式开发人员,我从未有过学习函数式编程的冲动.

Having been an imperative developer for some years now, I had never had the urge to learn functional programming.

几个月前,我终于决定学习 Haskell.这是一种很酷的语言,但我对事件驱动的真实应用程序如何用这种语言进行编程感到困惑.你知道关于它的好教程吗?

A couple months ago at last I decided to learn Haskell. It's quite a cool language, but I'm puzzled about how an event driven real app would be programmed in such a language. Do you know of a good tutorial about it?

注意:当我说真正的应用程序"时,我指的不是真实世界的、生产就绪的应用程序.我只是说一个小示例应用程序,只是为了掌握它.我认为类似简化版的 windows 计算器会很棒,然后可能会更复杂一些.

Note: When I say "real app" I'm not talking of a real world, production ready app. I just mean a little sample app, just to get the grasp of it. I think something like a simplified version of the windows caculator would be great, and then perhaps something a bit more complex.

推荐答案

当你说现实世界"的例子时,你大概是在考虑本质上是顺序的或有状态的问题,或者有很多 I/O 的问题,对吧?

When you say "real world" examples you are presumably thinking about problems that are inherently sequential or stateful or do lots of I/O, right?

那么,游戏呢?

  • Frag is a Quake clone, implemented for an undergraduate thesis (Functional Programming and 3D Games, Mun Hon Cheong, 2005). Here's a video of it in action.
  • Super Monao Bros. (formerly known as Super Nario Bros.) is, well, you can probably figure out which game it is a clone of. (This is the author's English language weblog.)
  • Purely Functional Retrogames is a 4-part series of blog articles about how to write games in a purely functional language, explained using Pacman as the example. (Part 2, Part 3, Part 4.)

或者,一个X Window Manager怎么样,一个可扩展的Emacs 克隆文本编辑器IDE?

Or, what about an X Window Manager, an extensible Emacs clone text editor or an IDE?

然后,这本书的标题中甚至已经包含了您的问题:Real World Haskell 免费提供

Then, there is the book, which even has your question already in the title: Real World Haskell and which is also available for free!

您可能想了解的另一件事是函数式响应式编程.(例如,它在 Frag 中使用.)关于 FRP 的有趣之处在于它允许您从一个非常不同的角度来看待 GUI 编程等问题.如果您阅读 RWH 书中的 GUI 一章,您会看到它讲述了如何像在 C 中一样编写 GUI 应用程序,只是更好.FRP OTOH 允许您以完全不同的方式编写它,甚至在 C 中不可能.

Another thing you might want to look at, is Functional Reactive Programming. (It is used in Frag, for example.) The interesting thing about FRP is that it allows you to look at the problem of, say, GUI programming from a very different angle. If you read the GUI chapter in the RWH book, you will see that it talks about how you can write a GUI application just like in C, only better. FRP OTOH allows you to write it in a totally different way that wouldn't even be possible in C.

很多时候(我不是说你的问题就是这种情况,但它是一种反复出现的模式)当有人说但是 Haskell 可以在现实世界中使用吗"时,他们是什么真的 说的是我知道如何在 C 中做到这一点,而在 Haskell 中我不能以完全相同的方式做到这一点,因此在 Haskell 中它一定是不可能的,因此 Haskell 还没有为现实世界做好准备".但他们错过的是,可能有一种完全不同且更好的方法来解决问题.(这就像是在说Erlang 没有线程,因此它不可能用于实现并发系统.")而 FRP 只是一个例子.

A lot of times (I'm not saying that this is the case in your question, but it is a recurring pattern) when someone says "but can Haskell be used in the real world", what they are really saying is "I know how to do this in C, and in Haskell I cannot do it in exactly the same way, therefore it must be impossible in Haskell, therefore Haskell is not ready for the real world". But what they are missing out on, is that there might be a totally different and much better way to solve the problem. (It's like saying "Erlang doesn't have threads, therefore it cannot possibly be used to implement concurrent systems.") And FRP is just one example.

这篇关于现实世界的 Haskell 编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆