[Haskell-cafe] GHC Extension Proposal: ArgumentBlock

Manuel Gómez targen at gmail.com
Tue Sep 8 16:48:53 UTC 2015


(Resending; forgot to include the list.  Sorry for the noise, Niklas.)

On Tue, Sep 8, 2015 at 10:05 AM, Niklas Larsson <metaniklas at gmail.com> wrote:
> I would be unhappy if GHC included gratuitous differences from the Haskell
> spec by default.

You must be quite unhappy.  From the GHC user manual:

§7.3.1. Unicode syntax: The language extension `-XUnicodeSyntax`
enables Unicode characters to be used to stand for certain ASCII
character sequences.

§7.3.2. The magic hash: The language extension `-XMagicHash` allows
`#` as a postfix modifier to identifiers. Thus, `x#` is a valid
variable, and `T#` is a valid type constructor or data constructor.
The hash sign does not change semantics at all.

§7.3.3. Negative literals: The literal `-123` is, according to
Haskell98 and Haskell 2010, desugared as `negate (fromInteger 123)`.
The language extension `-XNegativeLiterals` means that it is instead
desugared as `fromInteger (-123)`.

§7.3.4. Fractional looking integer literals: Haskell 2010 and Haskell
98 define floating literals with the syntax `1.2e6`. These literals
have the type `Fractional a => a`.  The language extension
`-XNumDecimals` allows you to also use the floating literal syntax for
instances of `Integral`, and have values like `(1.2e6 :: Num a => a)`.

§7.3.5. Binary integer literals: Haskell 2010 and Haskell 98 allows
for integer literals to be given in decimal, octal (prefixed by `0o`
or `0O`), or hexadecimal notation (prefixed by `0x` or `0X`).  The
language extension `-XBinaryLiterals` adds support for expressing
integer literals in binary notation with the prefix `0b` or `0B`. For
instance, the binary integer literal `0b11001001` will be desugared
into `fromInteger 201` when `-XBinaryLiterals` is enabled.

§7.3.10. `n+k` patterns: `n+k` pattern support is disabled by default.
To enable it, you can use the `-XNPlusKPatterns` flag.

§7.3.17. Postfix operators: The `-XPostfixOperators` flag enables a
small extension to the syntax of left operator sections, which allows
you to define postfix operators. The extension is this: the left
section `(e !)` is equivalent (from the point of view of both type
checking and execution) to the expression `((!) e)` (for any
expression `e` and operator `(!)`.  The strict Haskell 98
interpretation is that the section is equivalent to `(\y -> (!) e y)`.
That is, the operator must be a function of two arguments. GHC allows
it to take only one argument, and that in turn allows you to write the
function postfix.

§7.3.18. Tuple sections: The `-XTupleSections` flag enables
Python-style partially applied tuple constructors. For example, the
following program, `(, True)`, is considered to be an alternative
notation for the more unwieldy alternative `\x -> (x, True)`.

§7.3.19. Lambda-case: The `-XLambdaCase` flag enables expressions of
the form `\case { p1 -> e1; ...; pN -> eN }` which is equivalent to
`\freshName -> case freshName of { p1 -> e1; ...; pN -> eN }`

§7.3.20. Empty case alternatives: The `-XEmptyCase` flag enables case
expressions, or lambda-case expressions, that have no alternatives,
thus: `case e of { }`

§7.3.21. Multi-way if-expressions: With `-XMultiWayIf` flag GHC
accepts conditional expressions with multiple branches: `if | guard1
-> expr1 ; | ... ; | guardN -> exprN`, which is roughly equivalent to
`case () of _ | guard1 -> expr1 ; ... ; _ | guardN -> exprN`.

§7.3.23. Record puns: Record puns are enabled by the flag
`-XNamedFieldPuns`.  When using records, it is common to write a
pattern that binds a variable with the same name as a record field,
such as: `data C = C {a :: Int}; f (C {a = a}) = a`.  Record punning
permits the variable name to be elided, so one can simply write `f (C
{a}) = a` to mean the same pattern as above.

§7.3.24. Record wildcards: Record wildcards are enabled by the flag
`-XRecordWildCards`. […]  For records with many fields, it can be
tiresome to write out each field individually in a record pattern, as
in `data C = C {a :: Int, b :: Int, c :: Int, d :: Int}; f (C {a = 1,
b = b, c = c, d = d}) = b + c + d`.  Record wildcard syntax permits a
`..` in a record pattern, where each elided field `f` is replaced by
the pattern `f = f`.

§7.6.4. Overloaded string literals: GHC supports overloaded string
literals. Normally a string literal has type `String`, but with
overloaded string literals enabled (with `-XOverloadedStrings`) a
string literal has type `(IsString a) => a`.  This means that the
usual string syntax can be used, e.g., for `ByteString`, `Text`, and
other variations of string like types.

§7.6.5. Overloaded lists: GHC supports overloading of the list
notation. […]  This extension allows programmers to use the list
notation for construction of structures like: `Set`, `Map`, `IntMap`,
`Vector`, `Text` and `Array`.

Please, let’s not pretend there is anything extraordinary about GHC
extensions straying from the Haskell standards for mostly syntactical
reasons that could be convincingly argued to be gratuitous.  We have
plenty of that.  We have always had plenty of that.  Having plenty of
that has been significant in making Haskell a pleasant environment for
formal expression.

Support for stylistic diversity is a feature, not a bug.


More information about the Haskell-Cafe mailing list