I\'m using GHCi 7.0.3 with the following program that implements type-level list:
{-# LANGUAGE TypeOperators #-}
data True
data False
-- List
data Nil
data Con
The other answers are correct about enabling the extension in GHCi, either from the GHCi prompt or as a flag when starting GHCi. There is a third option, however--you can create a .ghci
file that will be loaded and run every time you start GHCi, and use that to enable the extension automatically. Particularly for things like TypeOperators
, where there's very little harm in having it enabled, it's nicely convenient.
For example, here's what mine looks like right now:
:set prompt "∀x. x ⊢ "
:set -XTypeOperators
import Control.Monad
import Control.Applicative
import Control.Arrow
The .ghci
file goes in whatever your system's standard location is for such files.
To answer your extended question: The code in question works in GHCi roughly because it would also work if used in another module, which imported the module using the pragmas but didn't enable them itself. GHC is more than capable of enabling extensions on a per-module basis, even when the exported definitions couldn't possibly make sense without an extension, or have inferred types that require it.
The distinction is a little fuzzy in GHCi because it also puts non-exported definitions from the module in scope, but in general anything that would work if used from another module will also work at the GHCi prompt.