What is Haskell actually useful for?

For instance, if I start learning Haskell, what can I find myself using it for. What are some common uses for this language that I hear is a functional one? What are some common uses for this language? Rapid application development. If you want to know "why Haskell?", then you need to consider advantages of functional programming languages (taken from http://c2.com/cgi/wiki?Advan

什么是Haskell实际上有用的?

例如,如果我开始学习Haskell,我可以找到自己使用它的原因。 我听说这种语言的一些常见用途是功能性的吗? 这种语言有哪些常见用途? 快速应用开发。 如果你想知道“为什么Haskell?”,那么你需要考虑函数式编程语言的优点(摘自http://c2.com/cgi/wiki?AdvantageOfFunctionalProgramming): 功能性程序往往比其强制性语言同行更为简洁。 通常这会提高程序员的生产力 FP鼓励快速成型。 因此,我认为这是ExtremePro

Use of Haskell state monad a code smell?

God I hate the term "code smell", but I can't think of anything more accurate. I'm designing a high-level language & compiler to Whitespace in my spare time to learn about compiler construction, language design, and functional programming (compiler is being written in Haskell). During the code generation phase of the compiler, I have to maintain "state"-ish dat

Haskell状态monad使用代码的气味?

上帝我讨厌“代码味道”这个词,但我想不出任何更准确的东西。 我在我的业余时间学习有关编译器施工,语言设计,和函数式编程设计高级语言和编译器空白(编译程序被写入在Haskell)。 在编译器的代码生成阶段,我必须在遍历语法树时维护“状态”数据。 例如,编译流程控制语句,当我需要生成标签唯一的名称跳到(从则传递中,更新计数器生成的标签,和返回,计数器的旧值必须永远不会被再次使用)。 另一个例子是,当我遇到的

How to read this GHC Core "proof"?

I wrote this small bit of Haskell to figure out how GHC proves that for natural numbers, you can only halve the even ones: {-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeFamilies #-} module Nat where data Nat = Z | S Nat data Parity = Even | Odd type family Flip (x :: Parity) :: Parity where Flip Even = Odd Flip Odd = Even data ParNat :: Parity -> * where PZ :: ParNat Even PS

如何阅读GHC Core的“证明”?

我写了这个Haskell的一小部分来弄清GHC如何证明对于自然数,你只能将一半的数减半: {-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeFamilies #-} module Nat where data Nat = Z | S Nat data Parity = Even | Odd type family Flip (x :: Parity) :: Parity where Flip Even = Odd Flip Odd = Even data ParNat :: Parity -> * where PZ :: ParNat Even PS :: (x ~ Flip y, y ~ Flip x) => ParNat x

bit dll on Windows with GHC?

What I am looking for is exporting my haskell module as a 64-bit dll. My setup is 64-bit Windows 7 and Haskell Platform 2013.2.0.0. I tried building with ghc --make -static -shared -fPIC ff.hs -o ff_dll.dll which works fine except for it produces 32-bit version (I managed to call it from another app). So my question is: is it possible to build 64-bit dll with GHC on Windows? You can get a

与GHC的Windows上的位DLL?

我正在寻找的是将我的haskell模块导出为64位dll。 我的设置是64位Windows 7和Haskell Platform 2013.2.0.0。 我试图用ghc --make -static -shared -fPIC ff.hs -o ff_dll.dll ,除了产生32位版本(我从另一个应用程序调用它)之外,它工作正常。 所以我的问题是:是否有可能在Windows上使用GHC构建64位dll? 您可以从官方GHC网站的下载部分获得64位GHC。 然后,您可以cabal install haskell-platform来构建通常随Platfor

Can't output from .hs to .hc with GHC in Haskell

I was intrigued when I heard that GHC can output a file to C . The Glasgow Haskell Compiler (GHC) compiles to native code on a number of different architectures—as well as to ANSI C—using C-- as an intermediate language. So I installed the Haskell Platform and created a simple .hs file. main = putStrLn "Hello, World!" And according to the manual. -C Stop after generating C (.hc file) No

使用GHC在Haskell中不能从.hs输出到.hc

当我听说GHC可以向C输出文件时,我很感兴趣。 格拉斯哥Haskell编译器(GHC)在许多不同的体系结构上编译为本地代码 - 以及ANSI C--使用C--作为中间语言。 所以我安装了Haskell平台并创建了一个简单的.hs文件。 main = putStrLn "Hello, World!" 并根据手册。 -C生成C(.hc文件)后停止 现在我运行命令。 ghc -C test.hs 但它不会创建.hc文件,也不会停止中间编译。 $ ls test.exe test.hi test.hs test.o 如果

Small Haskell program compiled with GHC into huge binary

Even trivially small Haskell programs turn into gigantic executables. I've written a small program, that was compiled (with GHC) to the binary with the size extending 7 MB! What can cause even a small Haskell program to be compiled to the huge binary? What, if anything, can I do to reduce this? Let's see what's going on, try $ du -hs A 13M A $ file A A: ELF 64-bit

用GHC编译成的小Haskell程序变成了巨大的二进制文件

即使是普通的小型Haskell程序也会变成巨大的可执行文件。 我写了一个小程序,它被编译(使用GHC)到大小为7 MB的二进制文件! 什么会导致一个小的Haskell程序被编译成巨大的二进制文件? 如果有的话,我能做些什么来减少这种情况? 让我们看看发生了什么,试试吧 $ du -hs A 13M A $ file A A: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/

Defining a new monad in haskell raises no instance for Applicative

I am trying to define a new monad and I am getting a strange error newmonad.hs newtype Wrapped a = Wrap {unwrap :: a} instance Monad Wrapped where (>>=) (Wrap x) f = f x return x = Wrap x main = do putStrLn "yay" $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.10.1 $ ghc newmonad.hs [1 of 1] Compiling Main ( newmonad.hs, newmonad.o ) newmonad

在haskell中定义新monad不会引发Applicative的实例

我正在尝试定义一个新的monad,并且出现一个奇怪的错误 newmonad.hs newtype Wrapped a = Wrap {unwrap :: a} instance Monad Wrapped where (>>=) (Wrap x) f = f x return x = Wrap x main = do putStrLn "yay" $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.10.1 $ ghc newmonad.hs [1 of 1] Compiling Main ( newmonad.hs, newmonad.o ) newmonad.hs:2:10: N

Techniques for Tracing Constraints

Here's the scenario: I've written some code with a type signature and GHC complains could not deduce x ~ y for some x and y . You can usually throw GHC a bone and simply add the isomorphism to the function constraints, but this is a bad idea for several reasons: It does not emphasize understanding the code. You can end up with 5 constraints where one would have sufficed (for example,

跟踪约束的技巧

以下是这种情况:我写了一些带有类型签名的代码,GHC抱怨无法为x和y推出x〜y。 您通常可以将GHC投入骨骼,并简单地将同构添加到函数约束中,但出于以下几个原因,这是一个糟糕的主意: 它不强调理解代码。 最终可以有5个约束条件,其中一个条件就足够了(例如,如果5条约定有一个更具体的约束条件) 如果您做错了某些事情,或者GHC没有任何帮助,您最终可能会受到虚假限制 我刚刚花了几个小时来对付案例3.我正在玩synta

Specialization with Constraints

I'm having problems getting GHC to specialize a function with a class constraint. I have a minimal example of my problem here: Foo.hs and Main.hs. The two files compile (GHC 7.6.2, ghc -O3 Main ) and run. NOTE: Foo.hs is really stripped down. If you want to see why the constraint is needed, you can see a little more code here. If I put the code in a single file or make many other minor

具有约束的专业化

我有问题让GHC专门化一个带有类限制的函数。 我在这里有一个我的问题的最小例子:Foo.hs和Main.hs. 这两个文件编译(GHC 7.6.2, ghc -O3 Main )并运行。 注意: Foo.hs真的被剥夺了。 如果你想知道为什么需要约束,你可以在这里看到更多的代码。 如果我将代码放在单个文件中或做出许多其他较小的更改,GHC只需将该调用内联到plusFastCyc 。 这在实际代码中不会发生,因为plusFastCyc对于GHC内联而言过大,即使标记为INL

Why does this Template Haskell work?

Consider this code: magic :: String -> Q Exp magic s = [e| putStrLn s |] Now, as best as I can tell, this shouldn't actually work. Inside the Oxford brackets, s is not in scope. And yet, the above apparently works perfectly. If we change this example slightly, it now breaks horribly: magic :: Exp -> Q Exp magic (VarE n) = [e| putStrLn (nameBase n) |] Just like before, we have a vari

为什么这个模板Haskell工作?

考虑这个代码: magic :: String -> Q Exp magic s = [e| putStrLn s |] 现在,尽我所知,这实际上并不适用。 在牛津括号内, s不在范围内。 然而,上述显然完美的作品。 如果我们稍微改变这个例子,它现在会破坏得很厉害: magic :: Exp -> Q Exp magic (VarE n) = [e| putStrLn (nameBase n) |] 就像以前一样,我们有一个不在范围内的变量。 这一次,它打破了。 但它并不抱怨一个不在范围内的变量; 相反,它会抱