Orphaned instances in Haskell

When compiling my Haskell application with the -Wall option, GHC complains about orphaned instances, for example: Publisher.hs:45:9: Warning: orphan instance: instance ToSElem Result The type class ToSElem is not mine, it's defined by HStringTemplate. Now I know how to fix this (move the instance declaration into the module where Result is declared), and I know why GHC would prefer to

Haskell中的孤立实例

当使用-Wall选项编译我的Haskell应用程序时,GHC会抱怨孤立的实例,例如: Publisher.hs:45:9: Warning: orphan instance: instance ToSElem Result Type类ToSElem不是我的,它由HStringTemplate定义。 现在我知道如何解决这个问题(将实例声明移到声明Result的模块中),我知道为什么GHC宁愿避免孤立的实例,但我仍然相信我的方式更好。 我不在乎编译器是否不方便 - 而不是我。 我想在Publisher模块中声明我的ToSEle

What does the `forall` keyword in Haskell/GHC do?

I'm beginning to understand how the forall keyword is used in so-called "existential types" like this: data ShowBox = forall s. Show s => SB s This is only a subset, however, of how forall is used and I simply cannot wrap my mind around its use in things like this: runST :: forall a. (forall s. ST s a) -> a Or explaining why these are different: foo :: (forall a. a ->

Haskell / GHC中的`forall`关键字是做什么的?

我开始了解如何在所谓的“存在类型”中使用forall关键字: data ShowBox = forall s. Show s => SB s 这仅仅是一个子集,但是,如何forall使用,我根本不能完成我的脑海里围绕其在这样的事情用途: runST :: forall a. (forall s. ST s a) -> a 或者解释为什么这些不同: foo :: (forall a. a -> a) -> (Char,Bool) bar :: forall a. ((a -> a) -> (Char, Bool)) 或者整个RankNTypes东西... 我倾向于选

What performance can I expect from Int32 and Int64?

I often see pprograms like this, where Int64 is an absolute performance killer on 32-bit platforms. My question is now: If I need a specific word length for my task (in my case a RNG), is Int64 efficient on 64-bit platforms or will it still use the C-calls? And how efficient is converting an Int64 to an Int ? on a 64bit system Int64 should be fine, I don't know for sure though. More i

我可以从Int32和Int64期望什么性能?

我经常看到像这样的pprogram,其中Int64是32位平台上的绝对性能杀手。 我现在的问题是: 如果我的任务需要特定的字长(在我的情况下是一个RNG),在64位平台上是Int64有效的,还是仍然使用C调用? 将Int64转换为Int效率如何? 在64位系统Int64应该没问题,但我不确定。 更重要的是,如果你使用加密或随机数生成,你必须使用算法所说的数据类型,同时注意签名。 如果你不这样做,你会得到错误的结果,这可能意味着你的密

Hindley do you not understand?"

I can't find it now, but I swear there used to be a T-shirt for sale featuring the immortal words: What part of do you not understand? In my case, the answer would be... all of it! In particular, I often see notation like this in Haskell papers, but I have no clue what any of it means. I have no idea what branch of mathematics it's supposed to be. I recognise the letters of the

欣德利你不明白吗?“

我现在找不到它,但我发誓曾经是一件出售不朽字的T恤衫: 什么部分 难道你不明白? 就我而言,答案就是......全部! 特别是,我经常在Haskell论文中看到这样的符号,但我不知道它的含义。 我不知道它应该是什么数学分支。 当然,我认识到希腊字母的字母,以及诸如“∉”之类的符号(通常意味着某物不是集合中的一个元素)。 另一方面,我从未见过“⊢”(维基百科声称它可能意味着“分区”)。 我也不熟悉在这里使用vincul

Getting started with Haskell

For a few days I've tried to wrap my head around the functional programming paradigm in 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. But since I don't really know what Haskell is capable of and because there

Haskell入门

几天来,我试图围绕Haskell中的函数式编程范例进行研究。 我通过阅读教程和观看屏幕录像来完成这一任务,但似乎没有任何关系。 现在,在学习各种命令/ OO语言(如C,Java,PHP)时,练习对我来说是一个好方法。 但是由于我并不真正了解Haskell的能力,并且因为有许多新的概念需要使用,所以我不知道从哪里开始。 那么,你是如何学习Haskell的? 是什么让你真的“破冰”? 还有,开始练习的好主意? 我将按照您在haskell中

What is a monad?

Having briefly looked at Haskell recently, what would be a brief, succinct, practical explanation as to what a monad essentially is? I have found most explanations I've come across to be fairly inaccessible and lacking in practical detail. First: The term monad is a bit vacuous if you are not a mathematician. An alternative term is computation builder which is a bit more descriptive of w

什么是monad?

最近简单地看了一下Haskell,对于monad实质上是什么而言,简单,简洁,实用的解释是什么? 我发现我所遇到的大部分解释都是相当难以获得的,并且缺乏实际的细节。 第一:如果你不是数学家, monad这个词有点空虚。 另一个术语是计算生成器 ,它对它们实际上有用的内容有更多描述。 你问一些实际的例子: 示例1:列表理解 : [x*2 | x<-[1..10], odd x] 该表达式返回1到10范围内所有奇数的双精度。非常有用! 事

Why can't a function take a type constrained only by a typeclass?

I don't have quite the vocabulary for phrasing this question (and therefore for searching for answers, so apologies if the answer is easily available). Consider the following class RunFoo m where runFoo :: m a -> a class RunFooWrapper m where doRunFoo :: (RunFoo n) => n a -> m a newtype RunFast a = RunFast a newtype RunSlow a = RunSlow a fooExample :: (RunFoo m) => m Boo

为什么一个函数只能被一个类型类型约束?

我没有足够的词汇来表达这个问题(因此,为了寻找答案,如果答案很容易获得,请致歉)。 考虑以下 class RunFoo m where runFoo :: m a -> a class RunFooWrapper m where doRunFoo :: (RunFoo n) => n a -> m a newtype RunFast a = RunFast a newtype RunSlow a = RunSlow a fooExample :: (RunFoo m) => m Bool fooExample = undefined fooWrapperExample :: (RunFooWrapper m) => m Bool fooWrappe

Compiling very large constants with GHC

Today I asked GHC to compile an 8MB Haskell source file. GHC thought about it for about 6 minutes, swallowing almost 2GB of RAM, and then finally gave up with an out-of-memory error. [As an aside, I'm glad GHC had the good sense to abort rather than floor my whole PC.] Basically I've got a program that reads a text file, does some fancy parsing, builds a data structure and then uses

用GHC编译非常大的常量

今天,我要求GHC编译一个8MB的Haskell源文件。 GHC想了大约6分钟,吞下了近2GB的内存,然后最终放弃了内存不足的错误。 [顺便说一下,我很高兴GHC有理由放弃而不是整个电脑。] 基本上我有一个程序读取一个文本文件,做一些花哨的解析,建立一个数据结构,然后使用show将其转储到一个文件中。 我没有在最终的应用程序中包含整个解析器和源数据,而是希望将生成的数据作为编译时常量。 通过在show的输出中添加一些额外的东

Why Haskell uses bottom instead of null in partial functions?

I'm reading about Haskell denotational semantics (http://en.wikibooks.org/wiki/Haskell/Denotational_semantics) and I fail to see why, in a type, bottom "value" is placed at another level compared to "normal" values, eg why it can't be pattern matched. I believe that pattern patching bottom would cause trouble as bottom denotes also non-terminating computations, but w

为什么Haskell在部分函数中使用bottom而不是null?

我正在阅读有关Haskell指称语义(http://en.wikibooks.org/wiki/Haskell/Denotational_semantics),我不明白为什么在一个类型中,底部“值”被放置在与“正常”相比较的另一个层次上,值,例如为什么它不能被模式匹配。 我认为模式修补底部会导致麻烦,因为底部也表示非终止计算,但为什么非终止计算和错误应该被视为相同? (我假设调用不支持的参数的部分函数可以被视为一个错误)。 如果所有的Haskell类型都包含一个模式匹

When is unsafeInterleaveIO unsafe?

Unlike other unsafe* operations, the documentation for unsafeInterleaveIO is not very clear about its possible pitfalls. So exactly when is it unsafe? I would like to know the condition for both parallel/concurrent and the single threaded usage. More specifically, are the two functions in the following code semantically equivalent? If not, when and how? joinIO :: IO a -> (a -> IO b) -> IO

什么时候不安全InterleaveIO不安全?

与其他不安全*操作不同,不安全unsafeInterleaveIO的文档不太清楚其可能存在的缺陷。 那么到底什么时候它不安全? 我想知道并行/并行和单线程使用情况。 更具体地说,下面的代码中的两个函数在语义上是否相同? 如果没有,何时以及如何? joinIO :: IO a -> (a -> IO b) -> IO b joinIO a f = do !x <- a !x' <- f x return x' joinIO':: IO a -> (a -> IO b) -> IO b