Whole-program compilers like MLton create optimized binaries in part to their ability to use the total source of the binary to perform partial evaluation: aggressively inlining constants and evaluating them until stuck—all during compilation! This has been explored public ally a bit in the Haskell space by Gabriel Gonzalez's Morte. Now my understanding is that Haskell does not do very muc
像MLton这样的全程序编译器创建优化的二进制文件,部分原因是它们能够使用二进制文件的总体来源来执行部分评估:在编译过程中积极地内联常量并评估它们,直到卡住为止! Gabriel Gonzalez的Morte在Haskell空间中公开探讨了这一点。 现在我的理解是,Haskell并没有做太多的工作 - 如果有的话。 我所理解的引用理由是分离编译是对立的。 这对于禁止跨源文件边界进行部分评估是有意义的,但似乎文件部分评估仍然是一种选择。
Some time ago I devised a little system to make compilation and testing of my Haskell programs a bit more comfortable. My project root looks as follows: ./bin/ ./bin/myMain ./bin/test ./interfaces/ ./obj/ ./src/ ./src/makefile ./src/MyLib.hs ./src/myMain.hs ./src/testSuite.hs myMain is the main module, whose imports are like those: import MyLib -- irrelevant content follows testSuite is simi
前一段时间,我设计了一个小系统,使我的Haskell程序的编译和测试更加舒适。 我的项目根目录如下所示: ./bin/ ./bin/myMain ./bin/test ./interfaces/ ./obj/ ./src/ ./src/makefile ./src/MyLib.hs ./src/myMain.hs ./src/testSuite.hs myMain是主要模块,其进口如下: import MyLib -- irrelevant content follows testSuite类似: import System.Exit import Test.HUnit import MyLib -- irrelevant content follows
From the docs for GHC 7.6: [Y]ou often don't even need the SPECIALIZE pragma in the first place. When compiling a module M, GHC's optimiser (with -O) automatically considers each top-level overloaded function declared in M, and specialises it for the different types at which it is called in M. The optimiser also considers each imported INLINABLE overloaded function, and specialises it
从GHC 7.6文档: [Y]你通常甚至不需要SPECIALIZE编译指示。 在编译模块M时,GHC的优化器(带-O)会自动考虑在M中声明的每个顶层重载函数,并将其专用于M中调用的不同类型。优化器还会考虑每个导入的INLINABLE重载函数,并专门用于它在M中被称为的不同类型。 和 此外,给定一个函数f的SPECIALIZE pragma,如果它们与SPECIALIZE pragma位于同一个模块中,或者它们是INLINABLE,GHC将自动为f调用的任何类重载函数创建专门化;
I'm having trouble understanding how Haskell (GHC) compiles programs, and how those programs are run. GHC is the canonical example of a nontrivial program written in Haskell. However, parts of GHC seem not to be written in Haskell, namely the runtime environment (in C/C--). Why is that? Performance reasons? (I am aware of this site and its friends, but cannot make much sense of them.)
我很难理解Haskell(GHC)如何编译程序以及如何运行这些程序。 GHC是用Haskell编写的一个非平凡程序的典型例子。 但是,GHC的一些部分看起来并没有写在Haskell中,即运行时环境(在C / C--中)。 这是为什么? 性能原因? (我知道这个网站和它的朋友,但无法理解它们。) 说到运行时环境:为什么编译语言需要一个? 不应该编译的程序是机器代码,而不是别的? 据我所知,运行时环境有点类似于虚拟机或字节码解释器,
Is there a simple answer: Why is GHC so big? OCaml: 2MB Python: 15MB SBCL: 9MB OpenJRE - 26MB GHC: 113MB Not interested in evangelism of "Why I shouldn't care about the size if Haskell is the right tool"; this is a technical question. It's a bit silly really. Every library that comes with GHC is provided in no less than 4 flavours : static dynamic profiled
有一个简单的答案:为什么GHC这么大? OCaml:2MB Python:15MB SBCL:9MB OpenJRE - 26MB GHC:113MB 对“如果Haskell是正确的工具,我为什么不应该关心它的大小”这种传福音不感兴趣; 这是一个技术问题。 这真的有点傻。 每个提供GHC的图书馆都提供不少于4种口味的图书: 静态的 动态 异形 GHCI GHCi版本只是在一个.o文件中链接在一起的静态版本。 其他三个版本都有自己的一套接口文件( .hi文件)
I have a file with some data in it. This data never changes and I want to make it available outside of the IO monad. How can I do that? Example (note that this is just an example, my data is not computable): primes.txt: 2 3 5 7 13 code.hs: primes :: [Int] primes = map read . words . unsafePerformIO . readFile $ "primes.txt" Is this a "legal" use of unsafePerformIO ? Are the
我有一个包含一些数据的文件。 这些数据永远不会改变,我想让它在IO monad之外可用。 我怎样才能做到这一点? 示例(请注意,这只是一个示例,我的数据不可计算): primes.txt: 2 3 5 7 13 code.hs: primes :: [Int] primes = map read . words . unsafePerformIO . readFile $ "primes.txt" 这是否是“合法”使用unsafePerformIO ? 有替代品吗? 您可以使用TemplateHaskell在编译时读取文件。 该文件的数据将
I'm trying to figure out monads in Haskell but didn't get too far yet. I found https://en.wikibooks.org/wiki/Haskell/Understanding_monads#cite_note-1 and several other tutorials/explanations, but none seems to be explaining the difference between the type constructor and the return function. As I understood the type constructor constructs a monad from a given value of the basic data
我试图找出Haskell中的单子,但没有太多。 我发现https://en.wikibooks.org/wiki/Haskell/Understanding_monads#cite_note-1和其他几个教程/解释,但似乎没有解释类型构造函数和返回函数之间的区别。 据我了解 类型构造函数根据基本数据类型的给定值构造monad。 所以它就像Java中的一个普通构造器,它从给定的参数构建一个新的实例。 return函数将类型构造函数应用于基本数据类型的给定值并返回构造的monad。 那么有
Are there functional languages that can specify, in the typechecker, whether or not a certain computation is guaranteed to terminate? Alternatively, can you do this in just Haskell? Regarding Haskell, in this answer the poster says that The usual way of thinking about this is that every Haskell type is "lifted"--it contains ⊥. That is, Bool corresponds to {⊥, True, False} rather t
是否有函数式语言可以在类型检查器中指定某个计算是否保证终止? 或者,你可以在Haskell中做到这一点吗? 关于Haskell,在这个答案中,海报说 通常的思考方式是每个Haskell类型都被“解除” - 它包含⊥。 也就是说, Bool对应于{⊥, True, False}而不仅仅是{True, False} 。 这表示Haskell程序不保证终止并可能有例外。 另一方面,关于Agda的这篇论文指出 正确的Agda程序是通过类型检查和终止检查的程序 也就是说,所有
Before Haskell 98, there were Haskell 1.0 through 1.4. It's pretty interesting to see the development throughout the years, as features were added to the earliest versions of standardized Haskell. For instance, the do-notation was first standardized by Haskell 1.3 (published 1996-05-01). In the Prelude , we find the following definitions (page 87): -- Monadic classes class Functor f w
在Haskell 98之前,有Haskell 1.0到1.4。 随着功能被添加到最早版本的标准化Haskell中,看到多年来的发展非常有趣。 例如,该符号首先由Haskell 1.3(1996-05-01出版)标准化。 在Prelude ,我们找到了以下定义(第87页): -- Monadic classes class Functor f where map :: (a -> b) -> f a -> f b class Monad m where (>>=) :: m a -> (a -> m b) -> m b (>
According to this article on denotational semantics for Haskell there is only one non-strict (non-bottom prreserving) function from Int to Int. to quote: it happens that there is only one prototype of a non-strict function of type Integer -> Integer: one x = 1 Its variants are constk x = k for every concrete number k. Why are these the only ones possible? Remember that one n can be n
根据这篇关于Haskell的指称语义的文章,从Int到Int只有一个非严格(非底部精修)函数。 去引用: 它发生的只有一个类型为Integer的非严格函数原型 - > Integer: 一个x = 1 对于每个具体数字k,它的变体是constk x = k。 为什么这些是唯一可能的? 请记住,一个n不能少于一个⊥定义。 由于Integer是一个平坦的域,两者必须相同。 从本质上讲,该类型签名的唯一非严格函数只能是常量函数。 我不遵循这个论点。