6.2.2. The magic hash¶
-
MagicHash
¶ Since: 6.8.1 Enables the use of the hash character (
#
) as an identifier suffix.
The language extension MagicHash
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. We tend to use variable
names ending in “#” for unboxed values or types (e.g. Int#
), but
there is no requirement to do so; they are just plain ordinary
variables. Nor does the MagicHash
extension bring anything into
scope. For example, to bring Int#
into scope you must import
GHC.Prim
(see Unboxed types and primitive operations); the MagicHash
extension then
allows you to refer to the Int#
that is now in scope. Note that
with this option, the meaning of x#y = 0
is changed: it defines a
function x#
taking a single argument y
; to define the operator
#
, put a space: x # y = 0
.
The MagicHash
also enables some new forms of literals (see
Unboxed types):
'x'#
has typeChar#
"foo"#
has typeAddr#
3#
has typeInt#
. In general, any Haskell integer lexeme followed by a#
is anInt#
literal, e.g.-0x3A#
as well as32#
.3##
has typeWord#
. In general, any non-negative Haskell integer lexeme followed by##
is aWord#
.3.2#
has typeFloat#
.3.2##
has typeDouble#