本文介绍了“let x = x in x”的含义是什么?和“数据浮动#”在Haskell的GHC.Prim中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了GHC.Prim的模块,发现GHC.Prim中的所有数据似乎都被定义为 data Float#,没有像 = A | B ,并且GHC.Prim中的所有函数被定义为 gtFloat#= let x = x in x



我的问题是这些定义是否有意义,它们是什么意思。



我检查了GHC.Prim的标题,如下所示

  { -  
这是一个生成的文件(由genprimopcode生成)。
这不是实际使用的代码。它唯一的目的是黑线鳕消耗

- }

我想这可能与问题有一些关系,谁能解释这对我来说很重要。

解决方案

这是神奇的:)

原始操作者和操作。它们被硬编码到编译器中,因此没有用于基元的数据构造函数,所有函数都是底部的,因为它们不一定在纯哈斯克尔中表示。

(Bottom代表一个洞,在一个haskell程序中,一个无限循环或者 undefined 都是底部的例子) p换言之

这些数据声明/函数提供对原始编译器内部的访问。 GHC.Prim存在导出这些原语,它并不实际实现它们或任何东西(例如,它的代码实际上并不有用)。所有这些都是在编译器中完成的。



这是针对需要优化 的代码。如果您认为您可能需要它,请参阅有关这些原语的有用在GHC

I looked at the module of GHC.Prim and found that it seems that all datas in GHC.Prim are defined as data Float# without something like =A|B, and all functions in GHC.Prim is defined as gtFloat# = let x = x in x.

My question is whether these definations make sense and what they mean.

I checked the header of GHC.Prim like below

{-
This is a generated file (generated by genprimopcode).
It is not code to actually be used. Its only purpose is to be
consumed by haddock.
-}

I guess it may have some relations with the questions and who could please explain that to me.

解决方案

It's magic :)

These are the "primitive operators and operations". They are hardwired into the compiler, hence there are no data constructors for primitives and all functions are bottom since they are necessarily not expressable in pure haskell.

(Bottom represents a "hole" in a haskell program, an infinite loop or undefined are examples of bottom)

To put it another way

These data declarations/functions are to provide access to the raw compiler internals. GHC.Prim exists to export these primitives, it doesn't actually implement them or anything (eg its code isn't actually useful). All of that is done in the compiler.

It's meant for code that needs to be extremely optimized. If you think you might need it, some useful reading about the primitives in GHC

这篇关于“let x = x in x”的含义是什么?和“数据浮动#”在Haskell的GHC.Prim中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 13:35