Reputation: 41
When a GHCi session loads a file with {-# LANGUAGE NoImplicitPrelude #-}
directive, it will unload most of the Prelude definitions:
GHCi, version 8.10.6: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /path/to/.ghci
[1 of 1] Compiling Main ( Main.hs, interpreted )
Ok, one module loaded.
<interactive>:1:1: error: Variable not in scope: main
> :i id
<interactive>:1:1: error: Not in scope: ‘id’
Some "fundamental" definitions stays imported, nevertheless:
> :i ->
type (->) :: * -> * -> *
data (->) a b
-- Defined in ‘GHC.Prim’
infixr -1 ->
> :i []
type [] :: * -> *
data [] a = [] | a : [a]
-- Defined in ‘GHC.Types’
> :i :
type [] :: * -> *
data [] a = ... | a : [a]
-- Defined in ‘GHC.Types’
infixr 5 :
>
What I want to know is: Is there more of such definitions available without importing Prelude? Is there a complete list of them, or a way to generate it?
A previous Google search for haskell no prelude
(expectedly) did not give something useful. The No import of Prelude page in Haskell Wiki mentions that:
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.
I did not find (or missed) any relevent information there; I don't know where to look in the rest of GHC User's Guide, either.
Upvotes: 4
Views: 109
Reputation: 10645
There is also (~)
which weirdly is not in scope if you use :i
, but it does give you its kind (with GHC 9.4.4):
ghci> :i (~)
<interactive>:1:1: error: Not in scope: ‘~’
ghci> :k (~)
(~) :: k -> k -> Constraint
Upvotes: 2
Reputation: 91837
I don't know where to find documentation or implementation code confirming this explicitly, but here is what I would expect the answer to be, and I can't disprove it. The definitions that "survive" NoImplicitPrelude are those that a Haskell programmer could not define themselves, i.e. those that use special syntax that GHC has to know about. You've already highlighted the special syntax for lists, and :
is included because it's not really a legal name for a user-defined identifier.
If you poke around, you will discover that tuples all exist as well. After that, you have to start getting philosophical about what you consider a "definition". Is it surprising that 0 still works? Or should that have been exiled because it uses Prelude.Num?
Upvotes: 4