什么是 GHC.Exts,它的内容是如何选择的?
What is GHC.Exts, and how were its contents chosen?
Haskell 标准库中的 GHC.Exts 模块声称它
is the Approved Way to get at GHC-specific extensions.
如果这是真的,它解释了包含特定于实现的常量,如 the constant representing the maximum size of a tuple and (presumably) non-portable debugging functions。
然而,它并没有解释为什么 sortWith
is in this module. Its implementation 对我来说看起来像正常的、便携的 Haskell。
我希望在 Data.List 和 Data.Sequence.
中看到它
我好像误解了GHC.Exts是什么,我不明白它的导出集合背后的底层逻辑,或者它导出的东西是大杂烩的一些历史原因。
那么, 的 GHC.Exts 是什么? 为什么它导出如此奇怪的东西?
这些功能和 Down
newtype are for a syntactic extension: Generalised (SQL-Like) List Comprehensions,通过 -XTransformListComp
启用。
此扩展引入了与这些功能相对应的关键字:
There are three new keywords: group
, by
, and using
. (The function
sortWith
is not a keyword; it is an ordinary function that is exported
by GHC.Exts
.)
这些函数在列表上工作,但它们确实属于一个扩展(GHC.Exts
是扩展的家)。
GHC.Exts
导出各种混合内容的原因是因为存在各种扩展混合。
如果您想了解更多信息,请参阅 Phil Wadler 和 Simon Peyton Jones 的 user guide page -- and for even more, the paper。这实际上非常令人兴奋,这是用户指南页面中的示例:
我截断了它,但你可以这样说:
[ .. | (name, dept, salary) <- employees
, then group by dept
, then sortWith by (sum salary)
, then take 5 ]
再举一个例子:
output = [x| y <- [1..5], x <- "hello"
, then group using inits]
产量:
["","h","he","hel","hell","hello","helloh","hellohe","hellohel","hellohell","hellohello","hellohelloh",...]
Haskell 标准库中的 GHC.Exts 模块声称它
is the Approved Way to get at GHC-specific extensions.
如果这是真的,它解释了包含特定于实现的常量,如 the constant representing the maximum size of a tuple and (presumably) non-portable debugging functions。
然而,它并没有解释为什么 sortWith
is in this module. Its implementation 对我来说看起来像正常的、便携的 Haskell。
我希望在 Data.List 和 Data.Sequence.
我好像误解了GHC.Exts是什么,我不明白它的导出集合背后的底层逻辑,或者它导出的东西是大杂烩的一些历史原因。
那么, 的 GHC.Exts 是什么? 为什么它导出如此奇怪的东西?
这些功能和 Down
newtype are for a syntactic extension: Generalised (SQL-Like) List Comprehensions,通过 -XTransformListComp
启用。
此扩展引入了与这些功能相对应的关键字:
There are three new keywords:
group
,by
, andusing
. (The functionsortWith
is not a keyword; it is an ordinary function that is exported byGHC.Exts
.)
这些函数在列表上工作,但它们确实属于一个扩展(GHC.Exts
是扩展的家)。
GHC.Exts
导出各种混合内容的原因是因为存在各种扩展混合。
如果您想了解更多信息,请参阅 Phil Wadler 和 Simon Peyton Jones 的 user guide page -- and for even more, the paper。这实际上非常令人兴奋,这是用户指南页面中的示例:
我截断了它,但你可以这样说:
[ .. | (name, dept, salary) <- employees
, then group by dept
, then sortWith by (sum salary)
, then take 5 ]
再举一个例子:
output = [x| y <- [1..5], x <- "hello"
, then group using inits]
产量:
["","h","he","hel","hell","hello","helloh","hellohe","hellohel","hellohell","hellohello","hellohelloh",...]