Having been an imperative developer for some years now, I had never had the urge to learn functional programming. 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? Note: When I say "real app" I'm not talki
多年来一直是一个必要的开发人员,我从来没有学过函数式编程的冲动。 几个月前我终于决定学习Haskell。 这是一种非常酷的语言,但我对于如何以这种语言编写事件驱动真实应用程序感到困惑。 你知道一个关于它的好教程吗? 注意:当我说“真正的应用程序”时,我并不是在谈论现实世界,生产就绪应用程序。 我只是指一个小样本应用程序,只是为了掌握它。 我认为像Windows caculator的简化版本会很棒,然后可能会更复杂一些。
I came across the following definition as I try to learn Haskell using a real project to drive it. I don't understand what the exclamation mark in front of each argument means and my books didn't seem to mention it. data MidiMessage = MidiMessage !Int !MidiMessage It's a strictness declaration. Basically, it means that it must be evaluated to what's called "weak normal he
我试图通过一个真正的项目来学习Haskell来驱动它,我遇到了以下定义。 我不明白每个争论前面的惊叹号是什么意思,我的书似乎没有提到它。 data MidiMessage = MidiMessage !Int !MidiMessage 这是一个严格的声明。 基本上,这意味着当创建数据结构值时,必须对所谓的“弱正常头部形式”进行评估。 我们来看一个例子,以便我们看到这意味着什么: data Foo = Foo Int Int !Int !(Maybe Int) f = Foo (2+2) (3+3) (4+4) (Just
In the chapter 19 of Real World Haskell a lot of the examples now fail due to the change of Control.Exception . That makes me think maybe some of the stuff in this book is actually obsolete and not worth studying anymore, after all it's been 6 years. My only other reference is Learn You a Haskell For Great Good, though it's a great book, it's much more basic compared with RWH. Ca
在真实世界Haskell的第19章中,由于Control.Exception的更改,现在很多示例都失败了。 这让我想,也许这本书中的一些内容实际上已经过时,不值得再学习了,毕竟已经有6年了。 我唯一的另一个参考是学习你一个Haskell For Great Good,虽然它是一本很棒的书,但它比RWH更基础。 是否有人在阅读本书之前请给出一些建议,说明哪些部分不再相关? 特别是本书后半部分的章节,例如软件事务内存,并发编程,套接字编程等。 编
I know a few programmers who keep talking about Haskell when they are among themselves, and here on SO everyone seems to love that language. Being good at Haskell seems somewhat like the hallmark of a genius programmer. Can someone give a few Haskell examples that show why it is so elegant / superior? The way it was pitched to me, and what I think is true after having worked on learning on H
我知道有几个程序员在他们之间一直在讨论Haskell,所以大家似乎都喜欢那种语言。 擅长Haskell似乎有点像天才程序员的标志。 有人可以给出几个Haskell例子,说明它为什么如此优雅/优越? 对我而言,以及我在认识Haskell一个月后认为是真实的事实是函数式编程以有趣的方式扭曲了你的大脑:它迫使你以不同的方式思考熟悉的问题:代替循环,考虑地图,折叠和过滤器等。一般来说,如果您对问题有不止一个视角,那么您可以更好地
To generate x86 assembly code, I have defined a custom type called X86 : data X86 a = X86 { code :: String, counter :: Integer, value :: (X86 a -> a) } This type is used in do-notation like the following. This makes it easy to write templates for generating if-statements, for-loops, etc... generateCode :: X86 () generateCode = do label1 <- allocateUniqueLabel label2 <- allocateUn
为了生成x86汇编代码,我定义了一个名为X86的自定义类型: data X86 a = X86 { code :: String, counter :: Integer, value :: (X86 a -> a) } 这种类型用于如下的符号。 这可以很容易地编写用于生成if语句,for循环等的模板。 generateCode :: X86 () generateCode = do label1 <- allocateUniqueLabel label2 <- allocateUniqueLabel jmp label1 label label1 jmp label2 label label2 指令是这样定
I'm writing a parser and a type checker in Haskell starting from BNFC. The main function of the type checker is implemented as follows: typecheck :: Program -> Err () typecheck (PDefs ds) = do env <- foldM (env (DFun typ id args _ _) -> updateFun env id (argTypes args,typ) ) (emptyEnv) (ds) mapM_ (checkDef env) ds where argTypes = map ((ADecl _ typ _)
我正在从BNFC开始编写一个解析器和Haskell中的类型检查器。 类型检查器的主要功能实现如下: typecheck :: Program -> Err () typecheck (PDefs ds) = do env <- foldM (env (DFun typ id args _ _) -> updateFun env id (argTypes args,typ) ) (emptyEnv) (ds) mapM_ (checkDef env) ds where argTypes = map ((ADecl _ typ _) -> typ) 其中PDefs , DFun和ADecl是语言的抽象语
In my humble opinion the answers to the famous question "What is a monad?", especially the most voted ones, try to explain what is a monad without clearly explaining why monads are really necessary. Can they be explained as the solution to a problem? Why do we need monads? We want to program only using functions . ("functional programming (FP)" after all). Then, we hav
在我的愚见中,对于着名问题“什么是单子?”的回答,尤其是最被投票的问题,试图解释什么是单子,而没有明确解释为什么单子是真正必要的。 他们能解释为解决问题的方法吗? 为什么我们需要monads? 我们只想使用函数进行编程。 (毕竟是“函数式编程(FP)”)。 那么,我们有第一个大问题。 这是一个程序: f(x) = 2 * x g(x,y) = x / y 我们怎么说先执行什么? 我们如何使用不超过函数形成一个有序的函数序列(即
Possible Duplicate: Creating unique labels in Haskell I've got a datatype Person and some input data from which I will create the Persons. I'd like to have each Person have its own ID (let's say integers [0..]). I could do this with recursion, but since I'm doing this in Haskell, I'd like to understand the monads. The State Monad is probably the best for this job, I su
可能重复: 在Haskell中创建独特的标签 我有一个数据类型Person和一些输入数据,我将从中创建Person。 我想让每个人都有自己的ID(比方说整数[0 ..])。 我可以用递归来做到这一点,但是因为我在Haskell中这样做,所以我想了解单子。 我想,Monad可能是这项工作的最佳选择。 事情是,我不是很懂很多东西:我什么时候进入monad(哪些函数可以使用内部函数),如何将它们放在一起,如何使'tick'函数前进等等。
I'm trying to grasp the State Monad and with this purpose I wanted to write a monadic code that would generate a sequence of random numbers using a Linear Congruential Generator (probably not good, but my intention is just to learn the State Monad, not build a good RNG library). The generator is just this (I want to generate a sequence of Bool s for simplicity): type Seed = Int random ::
我试图掌握State Monad,为此我想编写一个monadic代码,使用线性同余发生器生成一个随机数序列(可能不太好,但我的意图是学习State Monad,而不是建立一个好的RNG库)。 生成器就是这样(为了简单起见,我想生成一系列Bool s): type Seed = Int random :: Seed -> (Bool, Seed) random seed = let (a, c, m) = (1664525, 1013904223, 2^32) -- some params for the LCG seed' = (a*seed + c) `mod`
Suppose that class A a where m1 :: a -> a m2 :: a -> a m3 :: a -> a ... where it is possible to write default implementation for m2 and m3 by using m1. Is it better to leave m2 and m3 into A or write them as extra functions m2 :: A a => a -> a outside A? Or in other words, is worth to minimize the class API or does it matter? I checked (quickly) some style guide
假设 class A a where m1 :: a -> a m2 :: a -> a m3 :: a -> a ... 可以使用m1编写m2和m3的默认实现。 把m2和m3留给A还是把它们写成额外的函数m2 :: A a => a -> a外部? 或换句话说,是否值得尽量减少类API或者它有什么关系? 我(快速)检查了一些风格指南,如程序指南和大型设计问题中的一些链接以及一些书籍(工艺&rwh),但无法找到此类的建议。 如果有关于这类问题的演示文稿,博客