Repa performance versus lists

In the Numeric Haskell Repa Tutorial Wiki, there is a passage that reads (for context): 10.1 Fusion, and why you need it Repa depends critically on array fusion to achieve fast code. Fusion is a fancy name for the combination of inlining and code transformations performed by GHC when it compiles your program. The fusion process merges the array filling loops defined in the Repa library, wit

性能与列表的对比

在Numeric Haskell Repa Tutorial Wiki中,有一段文字(用于上下文): 10.1融合,以及为什么你需要它 修复严重取决于阵列融合以实现快速代码。 Fusion编译你的程序时,融合是GHC执行的内联和代码转换的组合。 融合过程将Repa库中定义的数组填充循环与您在自己的模块中编写的“worker”函数进行合并。 如果融合过程失败,那么产生的程序将比需要的慢得多,通常比使用普通Haskell列表的等效程序慢10倍。 另一方面,提供的融

Can GHC unpack enumerations on strict data fields?

In a comment on the previous question, I claimed: I have another benchmark to indicate ghc-7.4.1+llvm does unpacking of enumerations on strict data fields. In fact, after some experimentation, I believe that, in at least some simplistic cases, using an enumeration is at least as fast as, and actually might be more memory efficient (hence faster in a more realistic application) than using a ne

GHC可以在严格的数据字段上枚举枚举吗?

在对前一个问题的评论中,我声称: 我有另一个基准来表明ghc-7.4.1 + llvm会在严格的数据字段上对枚举进行解包。 事实上,经过一些实验后,我相信在至少一些简单的情况下,使用枚举至少与使用新类型的Word8一样快,并且实际上可能会更有效率(因此在更现实的应用中速度更快) (或Int),即使在数据类型的严格字段中使用时也是如此。 正如我在前一个问题中所说的,我在一个更现实的(但仍然很小)的环境中经历了类似的现象

Profiling GHC generated functions with `deriving` keyword

I am trying to optimize a Haskell program. In the profiler output, I see that a lot of time is spent inside compare and == functions. But, the GHC profiler doesn't tell me anything more than the module name of those functions. I guess these are the GHC generated functions using deriving Eq and Ord . I wonder if there is an easy way to pinpoint where the actual problem is. For instance, u

使用`derivation`关键字分析GHC生成的函数

我正在尝试优化一个Haskell程序。 在剖析器输出中,我看到compare和==函数花费了大量时间。 但是,GHC分析器没有告诉我任何超过这些函数的模块名称。 我想这些是使用派生Eq和Ord生成的GHC函数。 我想知道是否有一种简单的方法来查明实际问题在哪里。 例如,对这些函数使用{-# SCC "more-specific-name" #-} 。 使用-ddump-deriv转储GHC生成的实际派生实例的代码,然后获取代码并将其放在您自己明确定义的函数下

Specialization of polymorphic functions

In his talk “Classes, Jim, but not as we know them” Simon Peyton-Jones talks about how type classes are implemented in GHC by having polymorphic functions taking an extra parameter that is a dictionary with the correct functions for the type(s) given to the function. He then said that GHC often optimizes functions by special-casing functions and not actually passing this dictionary at runtime.

多态函数的专门化

在他的演讲“类,吉姆,但不是我们所知道的”中,Simon Peyton-Jones讨论了如何在GHC中实现类型类,方法是使多态函数采用额外参数,该参数是具有正确函数类型的字典,赋予该功能。 然后他说,GHC经常通过特殊外壳函数优化函数,而不是在运行时实际传递该字典。 然后他说这并不总是可能的,因为Haskell具有多态递归,所以即使你有整个程序,也不一定消除所有的多态性。 他这是什么意思? 什么是一个程序的例子,其中一个人不

Demangling typeclass functions in GHC profiler output

When profiling a Haskell program written in GHC, the names of typeclass functions are mangled in the .prof file to distinguish one instance's implementations of them from another. How can I demangle these names to find out which type's instance it is? For example, suppose I have the following program, where types Fast and Slow both implement Show : import Data.List (foldl') sum' = fo

GHC分析器输出中的Demangling类型类函数

在分析用GHC编写的Haskell程序时,typeclass函数的名称会在.prof文件中被破坏,以区分一个实例与另一个实例的实现。 我该如何取消这些名称以找出它是哪种类型的实例? 例如,假设我有以下程序,其中Fast和Slow两个类型都实现了Show : import Data.List (foldl') sum' = foldl' (+) 0 data Fast = Fast instance Show Fast where show _ = show $ sum' [1 .. 10] data Slow = Slow instance Show Slow where show

Static types, polymorphism and specialization

When I first learned Haskell, I very quickly came to love parametric polymorphism. It's a delightfully simple idea that works astonishingly well. The whole "if it compiles it usually works right" thing is mostly due to parametric polymorphism, IMHO. But the other day, something occurred to me. I can write foo as a polymorphic function. But when bar calls foo , it will do so wi

静态类型,多态和专业化

当我第一次了解Haskell时,我很快就喜欢参数多态。 这是一个非常简单的想法,效果惊人。 整个“如果它编译它通常工作正常”的事情主要是由于参数多态性,恕我直言。 但有一天,我发生了一些事情。 我可以将foo写成多态函数。 但是当bar调用foo ,它会使用一组特定的参数类型。 或者,如果bar本身是多态的,那么它的调用者将分配确定的类型。 通过归纳,看起来如果您要采用任何有效的Haskell程序并分析整个代码库,您可以静

What is indexed monad?

What is indexed monad and the motivation for this monad? I have read that it helps to keep track of the side effects. But the type signature and documentation doesn't lead me to anywhere. What would be an example of how it can help to keep track of side effects (or any other valid example)? As ever, the terminology people use is not entirely consistent. There's a variety of inspir

什么是索引monad?

什么是索引monad和这个monad的动机? 我已经读过,它有助于跟踪副作用。 但是型号签名和文档不会让我到任何地方。 什么是它可以如何帮助跟踪副作用(或任何其他有效的例子)的例子? 与以往一样,人们使用的术语并不完全一致。 有许多灵感来源于单子,但严格说来并不完全是概念。 术语“索引monad”是用于表征一个这样的概念的术语(包括“monadish”和“参数化monad”(Atkey的名字))中的一个。 (另一个这样的概念,如果

Monads in Haskell and Purity

My question is whether monads in haskell actually maintain hakell's purity, and if so how. Frequently I have read about how side effects are impure but that side effects are needed for useful programs (eg i/o). In the next sentence it is stated that haskell's solution to this is monads. Then monads are explained to some degree or another, but not really how they solve the side-effect p

单哈斯克尔和纯度

我的问题是haskell中的monad是否确实保持hakell的纯度,如果是的话。 我经常阅读有关副作用是如何不纯的,但是有用的程序(例如I / O)需要副作用。 在接下来的句子中,有人说Haskell解决这个问题的方法是单子。 然后,单子们在某种程度上被解释了,但是他们并没有真正解决副作用问题。 我已经看到了这个和这个,而我对这些答案的解释实际上是在我自己的读物中找到的 - IO monad的“行为”不是I / O本身,而是当它们执行时执

Is Haskell truly pure (is any language that deals with input and output outside the system)?

After touching on Monads in respect to functional programming, does the feature actually make a language pure, or is it just another "get out of jail free card" for reasoning of computer systems in the real world, outside of blackboard maths? EDIT: This is not flame bait as someone has said in this post, but a genuine question that I am hoping that someone can shoot me down with and

Haskell是否真正纯粹(是处理系统外输入和输出的任何语言)?

在涉及函数式编程方面的Monad之后,该功能实际上是否使语言变得纯粹,还是仅仅是另一种“摆脱监狱免费卡”,以便在黑板数学之外推理现实世界中的计算机系统? 编辑: 这不是有人在这篇文章中说过的火焰诱饵,而是一个真正的问题,我希望有人能够抨击我,并说,证明,这是纯粹的。 此外,我正在考虑关于其他不太纯粹的功能语言和一些使用良好设计并比较纯度的OO语言的问题。 到目前为止,在我的FP非常有限的世界里,我仍然没

What is Haskell missing for totality checking?

A total (functional) language is one in which everything can be shown to terminate. Obviously, there are lots of places where I don't want this - throwing exceptions is sometimes handy, a web-server isn't supposed to terminate, etc. But sometimes, I would like a local totality check to enable certain optimizations. For example, if I have a provably-total function commutativity :: foral

Haskell缺少整体检查的内容?

总(功能性)语言是一切可以显示终止的语言。 显然,有很多地方我不希望这样 - 抛出异常有时很方便,Web服务器不应该终止,等等。但有时候,我想要一个局部总体检查来启用某些优化。 例如,如果我有一个可证明的全部功能 commutativity :: forall (n :: Nat) (m :: Nat). n + m :~: m + n commutativity = ... 那么,因为:~:只有一个居民( Refl ),GHC可以优化 gcastWith (commutativity @n @m) someExpression ==> s