The base-compat package

[ Tags: compatibility, library, mit ] [ Propose Tags ]

Provides functions available in later versions of base to a wider range of compilers, without requiring you to use CPP pragmas in your code. See the README for what is covered. Also see the changelog for recent changes.

Note that base-compat does not add any orphan instances. There is a separate package base-orphans for that.

[Skip to Readme]


Versions 0.0.0, 0.1.0,, 0.2.0,,, 0.2.1, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.5.0, 0.6.0, 0.7.0, 0.7.1, 0.8.0,, 0.8.1,, 0.8.2, 0.9.0, 0.9.1, 0.9.2, 0.9.3 (info)
Change log CHANGES.markdown
Dependencies base (>=4.3 && <5), unix [details]
License MIT
Copyright (c) 2012-2015 Simon Hengel, (c) 2014 João Cristóvão, (c) 2015 Ryan Scott
Author Simon Hengel <>, João Cristóvão <>, Ryan Scott <>
Maintainer Simon Hengel <>, João Cristóvão <>, Ryan Scott <>
Category System
Source repo head: git clone
Uploaded Sat Apr 25 01:37:14 UTC 2015 by ryanglscott
Updated Thu Sep 17 18:24:50 UTC 2015 by ryanglscott to revision 1   [What is this?]
Distributions Arch:0.9.3, Debian:0.8.2, Fedora:0.9.1, LTSHaskell:0.9.3, NixOS:0.9.3, Stackage:0.9.3, openSUSE:0.9.3
Downloads 118030 total (390 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-04-25 [all 1 reports]
Hackage Matrix CI




Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Readme for base-compat-0.8.1

[back to package description]

A compatibility layer for base Hackage version Build Status


The scope of base-compat is to provide functions available in later versions of base to a wider (older) range of compilers.

In addition, successful library proposals that have been accepted to be part of upcoming versions of base are also included. This package is not intended to replace base, but to complement it.

Note that base-compat does not add any orphan instances. There is a separate package base-orphans for that.

Basic usage

In your cabal file, you should have something like this:

  build-depends:      base              >= 4.3
                    , base-compat       >= 0.8.0

Then, lets say you want to use the isRight function introduced with base- Replace:

import Data.Either


import Data.Either.Compat

Note (1): There is no need to import both unqualified. The .Compat modules re-exports the original module.

Note (2): If a given module .Compat version is not defined, that either means that:

  • The module has not changed in recent base versions, thus no .Compat is needed.
  • The module has changed, but the changes depend on newer versions of GHC, and thus are not portable.
  • The module has changed, but those changes have not yet been merged in base-compat: patches are welcomed!

Using Prelude.Compat

If you want to use Prelude.Compat (which provides all the AMP/Traversable/Foldable changes from base-, it's best to hide Prelude, e.g.:

import Prelude ()
import Prelude.Compat

main :: IO ()
main = mapM_ print (Just 23)

Alternatively, you can use the NoImplicitPrelude language extension:

{-# LANGUAGE NoImplicitPrelude #-}
import Prelude.Compat

main :: IO ()
main = mapM_ print (Just 23)

Note that we use

mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()

from Data.Foldable here, which is only exposed from Prelude since base-

Using this approach allows you to write code that works seamlessly with all versions of GHC that are supported by base-compat.

What is covered

So far the following is covered.

For compatibility with the latest released version of base

  • Prelude.Compat incorporates the AMP/Foldable/Traversable changes and exposes the same interface as Prelude from base-
  • System.IO.Error.catch is not re-exported from Prelude.Compat for older versions of base
  • Text.Read.Compat.readMaybe
  • Text.Read.Compat.readEither
  • Data.Monoid.Compat.<>
  • Added bool function to Data.Bool.Compat
  • Added isLeft and isRight to Data.Either.Compat
  • Added withMVarMasked function to Control.Concurrent.MVar.Compat
  • Added (<$!>) function to Control.Monad.Compat
  • Added ($>) and void functions to Data.Functor.Compat
  • (&) function to Data.Function.Compat
  • ($>) and void functions to Data.Functor.Compat
  • dropWhileEnd, isSubsequenceOf, sortOn, and uncons functions to Data.List.Compat
  • makeVersion function to Data.Version.Compat
  • traceId, traceShowId, traceM, and traceShowM functions to Debug.Trace.Compat
  • calloc and callocBytes functions to Foreign.Marshal.Alloc.Compat
  • callocArray and callocArray0 functions to Foreign.Marshal.Array.Compat
  • Added Data.List.Compat.scanl'
  • lookupEnv, setEnv and unsetEnv to System.Environment.Compat

Supported versions of GHC/base

  • ghc-7.10.1 / base-
  • ghc-7.8.4 / base-
  • ghc-7.8.3 / base-
  • ghc-7.8.2 / base-
  • ghc-7.8.1 / base-
  • ghc-7.6.3 / base-
  • ghc-7.6.2 / base-
  • ghc-7.6.1 / base-
  • ghc-7.4.2 / base-
  • ghc-7.4.1 / base-
  • ghc-7.2.2 / base-
  • ghc-7.2.1 / base-
  • ghc-7.0.4 / base-
  • ghc-7.0.3 / base-
  • ghc-7.0.2 / base-
  • ghc-7.0.1 / base-

Patches are welcome; add tests for new code!


For Prelude.Compat there is an Prelude.index file that was generated from the output of

ghc --show-iface Prelude.hi

To verify that Prelude.Compat matches the specification given in Prelude.types run: