aboutsummaryrefslogtreecommitdiff
path: root/haddock-library/src/CompatPrelude.hs
blob: 60fa94d9859cdc3713e12a76992b12d87edb3024 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE CPP #-}

#if !MIN_VERSION_base(4,5,0)
# error This module doesn't provide compat-shims for versions prior to base-4.5
#endif

-- | Bridge impedance mismatch of different @base@ versions back till @base-4.5@ (GHC 7.4.2)
module CompatPrelude
    ( ($>)
    , isSymbolChar
    ) where

#if MIN_VERSION_base(4,7,0)
import           Data.Functor                ( ($>) )
#else
import           Data.Functor                ( (<$) )
#endif

#if MIN_VERSION_base(4,9,0)
import           Text.Read.Lex                      (isSymbolChar)
#else
import           Data.Char (GeneralCategory(..), generalCategory)
#endif


#if !MIN_VERSION_base(4,7,0)
infixl 4 $>

-- | Flipped version of '<$'.
--
-- @since 4.7.0.0
($>) :: Functor f => f a -> b -> f b
($>) = flip (<$)
#endif

#if !MIN_VERSION_base(4,9,0)
-- inlined from base-4.10.0.0
isSymbolChar :: Char -> Bool
isSymbolChar c = not (isPuncChar c) && case generalCategory c of
    MathSymbol           -> True
    CurrencySymbol       -> True
    ModifierSymbol       -> True
    OtherSymbol          -> True
    DashPunctuation      -> True
    OtherPunctuation     -> c `notElem` "'\""
    ConnectorPunctuation -> c /= '_'
    _                    -> False
  where
    -- | The @special@ character class as defined in the Haskell Report.
    isPuncChar :: Char -> Bool
    isPuncChar = (`elem` (",;()[]{}`" :: String))
#endif