简体   繁体   English

什么是GHC.Exts,它的内容是如何选择的?

[英]What is GHC.Exts, and how were its contents chosen?

The GHC.Exts module in the Haskell standard library claims that it Haskell标准库中的GHC.Exts模块声称它

is the Approved Way to get at GHC-specific extensions. 是获得GHC特定扩展的批准方式。

If that's true, it explains the inclusion of implementation-specific constants like the constant representing the maximum size of a tuple and (presumably) non-portable debugging functions . 如果这是真的,它解释了包含特定于实现的常量,例如表示元组的最大大小的常量和(可能)非便携式调试函数

However, it doesn't explain why sortWith is in this module. 但是,它没有解释为什么sortWith在这个模块中。 Its implementation looks like normal, portable Haskell to me. 它的实现看起来像普通的,可移植的Haskell给我。 I'd expect to see it in, eg, Data.List and Data.Sequence. 我希望能看到它,例如Data.List和Data.Sequence。

It seems I misunderstand what GHC.Exts is, I don't understand the underlying logic behind its collection of exports, or there's some historical reason it exports a hodgepodge of things. 我似乎误解了GHC.Exts是什么,我不理解其出口集合背后的基本逻辑,或者它有一些历史原因它出口大杂烩。

So, what is GHC.Exts for ? 那么, 什么是GHC.Exts for and why does it export such a weird mixture of stuff ? 为什么它会出口这种奇怪的混合物呢?

Those functions and the Down newtype are for a syntactic extension: Generalised (SQL-Like) List Comprehensions , enabled with -XTransformListComp . 这些函数和Down newtype用于语法扩展: 通用(SQL-Like)列表 -XTransformListComp ,使用-XTransformListComp启用。

This extension introduces keywords that correspond to those functions: 此扩展程序引入了与这些功能对应的关键字:

There are three new keywords: group , by , and using . 有三个新关键字: groupbyusing (The function sortWith is not a keyword; it is an ordinary function that is exported by GHC.Exts .) (函数sortWith不是关键字;它是由GHC.Exts导出的普通函数。)

Those functions are working on lists, but they really belong to an extension (and GHC.Exts is the extensions' home). 这些函数正在列表中,但它们实际上属于扩展( GHC.Exts是扩展的主页)。

And the reason GHC.Exts exports a varied mixture of stuff is because there are a varied mixture of extensions. GHC.Exts出口各种各样的东西的原因是因为有各种各样的扩展。

If you'd like to see more, see the user guide page -- and for even more, the paper for it by Phil Wadler and Simon Peyton Jones. 如果您想了解更多信息,请参阅用户指南页面 - 更多信息,请参阅Phil Wadler和Simon Peyton Jones撰写的论文 It's actually quite exciting imo, here's an example from the user guide page: 这实际上非常令人兴奋,这是用户指南页面中的一个例子:

I truncated it, but you can say stuff like: 我截断它,但你可以说:

[ .. | (name, dept, salary) <- employees
, then group by dept
, then sortWith by (sum salary)
, then take 5 ]

And as another example: 另一个例子:

output = [x| y <- [1..5], x <- "hello"
, then group using inits]

Yields: 产量:

["","h","he","hel","hell","hello","helloh","hellohe","hellohel","hellohell","hellohello","hellohelloh",...]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM