How to fix “Illegal datatype context” in Haskell

2011-10-26

I've finally updated my LibZip library to support GHC 7.2.1. Now it should be installable with usual cabal update and cabal install LibZip on any GHC from 6.12.1 up to 7.2.1 (I tested on three versions in between).

What I learned: datatype contexts are removed from the language. From the practical point of view, just deleting the contexts from datatype definitions should work most of the time on GHC >= 7.2.

When I had

data (Enum a, Storable a, Storable st) => PureSource a st = PureSource {
 -- blah-blah
}

I got this error:

Codec/Archive/LibZip.hs:369:6:
    Illegal datatype context (use -XDatatypeContexts): (Enum a,
                                                        Storable a,
                                                        Storable st) =>

With

data PureSource a st = PureSource {
  -- blah-blah
}

everything just works fine on GHC 7.2.1 and on previous versions of the compiler.