Personal tools

No import of Prelude

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(from Haskell-Cafe)
Current revision (15:26, 15 November 2011) (edit) (undo)
(Answer: Added newer -X version of command line switch)
 
(3 intermediate revisions not shown.)
Line 1: Line 1:
== Question ==
== Question ==
-
Is it possible not to load Prelude module when compiling a Haskell module?
+
Is it possible to not load the Prelude when compiling a Haskell module?
== Answer ==
== Answer ==
Line 15: Line 15:
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoImplicitPrelude #-}
</haskell>
</haskell>
-
to the top of the module, or equivalently compile with <code>-fno-implicit-prelude</code> option.
+
to the top of the module, or equivalently compile with <code>-XNoImplicitPrelude</code> (or older <code>-fno-implicit-prelude</code>) option.
-
<hask>import Prelude()<hask> is less aggressive than <code>NoImplicitPrelude</code>.
+
<hask>import Prelude()</hask> is less aggressive than <code>NoImplicitPrelude</code>.
-
E.g. with the first method <hask>fromInteger</hask> is still imported. It is silently inserted for number literals.
+
E.g. with the first method some functions are imported which are silently inserted for several syntactic constructs.
 +
A bare untyped integral number is rewritten as <hask>fromIntegral num</hask>
 +
(so its type will be <hask>Num a => a</hask>),
 +
and list generation syntax is rewritten as follows:
 +
<hask>[n..]</hask> <math>\rightarrow</math> <hask>enumFrom</hask>,
 +
<hask>[n..m]</hask> <math>\rightarrow</math> <hask>enumFromTo</hask>,
 +
<hask>[n,o..]</hask> <math>\rightarrow</math> <hask>enumFromThen</hask>,
 +
<hask>[n,o..m]</hask> <math>\rightarrow</math> <hask>enumFromThenTo</hask>.
 +
 
 +
There are some such for which even <code>-fno-implicit-prelude</code> isn't enough;
 +
I think these are documented in the "bugs" section of the GHC manual.
== See also ==
== See also ==

Current revision

1 Question

Is it possible to not load the Prelude when compiling a Haskell module?

2 Answer

You can either do

import Prelude()

or add

{-# LANGUAGE NoImplicitPrelude #-}

to the top of the module, or equivalently compile with -XNoImplicitPrelude (or older -fno-implicit-prelude) option.

import Prelude()
is less aggressive than NoImplicitPrelude.

E.g. with the first method some functions are imported which are silently inserted for several syntactic constructs.

A bare untyped integral number is rewritten as
fromIntegral num
(so its type will be
Num a => a
),

and list generation syntax is rewritten as follows:

[n..]
\rightarrow
enumFrom
,
[n..m]
\rightarrow
enumFromTo
,
[n,o..]
\rightarrow
enumFromThen
,
[n,o..m]
\rightarrow
enumFromThenTo
.

There are some such for which even -fno-implicit-prelude isn't enough; I think these are documented in the "bugs" section of the GHC manual.

3 See also