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

Jim Witschey

The GHC.Exts module in the Haskell standard library claims that it

is the Approved Way to get at GHC-specific extensions.

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. Its implementation looks like normal, portable Haskell to me. I'd expect to see it in, e.g., Data.List and 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.

So, what is GHC.Exts for? and why does it export such a weird mixture of stuff?

MasterMastic

Those functions and the Down newtype are for a syntactic extension: Generalised (SQL-Like) List Comprehensions, enabled with -XTransformListComp.

This extension introduces keywords that correspond to those functions:

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.)

Those functions are working on lists, but they really belong to an extension (and GHC.Exts is the extensions' home).

And the reason GHC.Exts exports a varied mixture of stuff is because there are a varied mixture of extensions.

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. 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",...]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How were the Locale constants chosen?

What are .xsh files? How to see its contents?

Compilation of a file as if its contents were in specified package

How do I remove copies of GHC that were installed by Stack?

How did the map2_dbl know what its arguments were in this instance?

GHC incompatibility installing haskell-src-exts via cabal

backtrack value which were chosen

display contents of chosen .txt file

How to know what plugins were installed in wordpress

How to see on what words the clusters were based on

Why were curly braces chosen for the format specifier?

How to download a directory and its contents using PSFTP?

How to pull a string apart by its contents

How to expand a div and its contents on hover?

How to make GridView wrap its contents in XAML?

How to ignore a folder and its contents in git?

How to clone ArrayList and also clone its contents?

How to properly load a URL and access its contents

How to refresh contents of Fragment through its Activity?

How to delete a folder by using its contents as a reference?

How to know what is the name in my chosen row in db?

How to know what item is chosen from array using random library?

Is there a more efficient way to reset the contents of cells that have been edited in a JTable back to what they previously were

zfs: what consumes the space difference between a zpool and its contents?

How to replace a key:value pair by its value whereever the chosen key occurs in a many-times-nested dictionary?

Its printing "No valid datasets were created." What can be the error in this code?

How to check what additional props were passed into a react component that were not defined?

How do I see what files were changed by the "ed" command?

What does nvprof output: "No kernels were profiled" mean, and how to fix it