-- We use -XMagicHash instead of the LANGUAGE pragma since we can't
-- CPP-guard language extensions on older versions of GHC.
{-# OPTIONS_GHC -Wall -fwarn-tabs -XMagicHash #-}
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 701
-- N.B., GHC.Exts isn't "safe".
{-# LANGUAGE Trustworthy #-}
#endif
----------------------------------------------------------------
--                                                    2021.10.17
-- |
-- Module      :  Prelude.SafeEnum
-- Copyright   :  2012--2021 wren gayle romano
-- License     :  BSD3
-- Maintainer  :  wren@cpan.org
-- Stability   :  provisional
-- Portability :  Haskell98 + CPP (+ MagicHash)
--
-- A redefinition of the "Prelude"\'s 'Prelude.Enum' class in order
-- to render it safe. That is, the Haskell Language Report defines
-- 'Prelude.pred', 'Prelude.succ', 'Prelude.fromEnum' and
-- 'Prelude.toEnum' to be partial functions when the type is
-- 'Bounded'[1], but this is unacceptable. So these classes are
-- offered as a replacement, correcting the types of those functions.
-- We intentionally clash with the names of the Prelude's class;
-- if you wish to use both in the same file, then import this module
-- (or the Prelude) qualified.
--
-- While we're at it, we also generalize the notion of enumeration.
-- Rather than requiring that the type is linearly enumerable, we
-- distinguish between forward enumeration (which allows for multiple
-- predecessors) and backward enumeration (which allows for multiple
-- successors). Moreover, we do not require that the enumeration
-- order coincides with the 'Ord' ordering (if one exists), though
-- it's advisable that they do (for your sanity). However, we also
-- ensure that the notion of enumeration (in either direction) is
-- well-defined, which rules out instances for 'Float' and 'Double',
-- and renders instances for 'Data.Ratio.Ratio' problematic.
-- 'Data.Ratio.Ratio' instances /can/ be provided so long as the
-- base type is integral and enumerable; but they must be done in
-- an obscure order[2] that does not coincide with 'Ord'. Since
-- this is not what people may expect, we only provide an instance
-- for the newtype 'Data.Number.CalkinWilf.CalkinWilf', not for
-- 'Data.Ratio.Ratio' itself.
--
-- The @MagicHash@ extension is only actually required if on GHC.
-- This extension is used only so that the implementation of the
-- instances for 'Char' match those of the Prelude's 'Prelude.Enum'.
-- I have not benchmarked to determine whether this low-level hackery
-- is actually still necessary.
--
-- [1] <http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1310006.3.4>
--
-- [2] Jeremy Gibbons, David Lester, and Richard Bird (2006).
--     /Enumerating the Rationals/. JFP 16(3):281--291.
--     DOI:10.1017\/S0956796806005880
--     <http://www.cs.ox.ac.uk/jeremy.gibbons/publications/rationals.pdf>
----------------------------------------------------------------
module Prelude.SafeEnum
    ( UpwardEnum(..)
    , DownwardEnum(..)
    , Enum(..)
    ) where

import Prelude hiding (Enum(..))
import qualified Prelude (Enum(..))

#ifdef __GLASGOW_HASKELL__
#   if __GLASGOW_HASKELL__ >= 708
import GHC.Exts (isTrue#, (/=#))
#   else
import GHC.Exts ((==#))
#   endif
import GHC.Exts (build, Int(I#), Char(C#), ord#, chr#, (<=#), (+#), (-#), leChar#)
#else
import Data.Char (chr, ord)
#endif
----------------------------------------------------------------
----------------------------------------------------------------
infix 4 `precedes`, `succeeds`


----------------------------------------------------------------
-- | A class for upward enumerable types. That is, we can enumerate
-- larger and larger values, eventually getting every one of them;
-- i.e., given any @x@, for all @y@ such that @y \`succeeds\` x@,
-- it must be the case that @y@ occurs within some finite prefix
-- of @enumFrom x@.
--
-- We require that 'succeeds' forms a strict partial order. That
-- is, it must obey the following laws (N.B., if the first two laws
-- hold, then the third one follows for free):
--
-- > if x `succeeds` y && y `succeeds` z then x `succeeds` z
-- > if x `succeeds` y then not (y `succeeds` x)
-- > not (x `succeeds` x)
--
-- Moreover, we require that 'succeeds' agrees with 'succ', and
-- that 'succ' is exhaustive for 'succeeds' (assuming @Eq a@, by
-- magic if need be):
--
-- > if succ x == Just y then y `succeeds` x
-- > if x `succeeds` y   then x `elem` enumFrom y
--
-- Minimal complete definition: 'succ', 'succeeds'.
class UpwardEnum a where

    -- | The successor of a value, or @Nothing@ is there isn't one.
    -- For the numeric types in the Prelude, 'succ' adds 1.
    succ :: a -> Maybe a

    -- | A variant of @('>')@ with regards to the enumeration order.
    succeeds :: a -> a -> Bool

    -- converse well-founded ~ Noetherian
    -- | Return @x@ followed by all it's successors, in order. The
    -- resulting list is always non-empty, since it includes @x@.
    -- If the resulting list is always finite, then the 'succeeds'
    -- ordering is converse well-founded. In GHC, the default
    -- implementation is a \"good producer\" for list fusion.
    enumFrom :: a -> [a]
#ifdef __GLASGOW_HASKELL__
    {-# INLINE enumFrom #-}
    enumFrom a
x0 = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (a -> (a -> b -> b) -> b -> b
forall t t. UpwardEnum t => t -> (t -> t -> t) -> t -> t
enumFromFB a
x0)
        where
        {-# INLINE [0] enumFromFB #-}
        enumFromFB :: t -> (t -> t -> t) -> t -> t
enumFromFB t
x t -> t -> t
cons t
nil = t
x t -> t -> t
`cons`
            case t -> Maybe t
forall a. UpwardEnum a => a -> Maybe a
succ t
x of
            Maybe t
Nothing -> t
nil
            Just t
y  -> t -> (t -> t -> t) -> t -> t
enumFromFB t
y t -> t -> t
cons t
nil
#else
    enumFrom x = x :
        case succ x of
        Nothing -> []
        Just y  -> enumFrom y
#endif

    -- | Return the elements of @'enumFrom' x@, filtering out
    -- everything that succeeds @z@. If @x@ succeeds @z@, then the
    -- resulting list is empty; otherwise, it is non-empty, since
    -- it includes @x@. In GHC, the default implementation is a
    -- \"good producer\" for list fusion.
    enumFromTo :: a -> a -> [a]
#ifdef __GLASGOW_HASKELL__
    {-# INLINE enumFromTo #-}
    enumFromTo a
x0 a
z0 = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (a -> a -> (a -> b -> b) -> b -> b
forall t t. UpwardEnum t => t -> t -> (t -> t -> t) -> t -> t
enumFromToFB a
x0 a
z0)
        where
        {-# INLINE [0] enumFromToFB #-}
        enumFromToFB :: t -> t -> (t -> t -> t) -> t -> t
enumFromToFB t
x t
z t -> t -> t
cons t
nil
            |  t
x t -> t -> Bool
forall a. UpwardEnum a => a -> a -> Bool
`succeeds` t
z = t
nil
            | Bool
otherwise       = t
x t -> t -> t
`cons`
                case t -> Maybe t
forall a. UpwardEnum a => a -> Maybe a
succ t
x of
                Maybe t
Nothing -> t
nil
                Just t
y  -> t -> t -> (t -> t -> t) -> t -> t
enumFromToFB t
y t
z t -> t -> t
cons t
nil
#else
    enumFromTo x z
        |  x `succeeds` z = []
        | otherwise       = x :
            case succ x of
            Nothing -> []
            Just y  -> enumFromTo y z
#endif


----------------------------------------------------------------
-- | A class for downward enumerable types. That is, we can enumerate
-- smaller and smaller values, eventually getting every one of them;
-- i.e., given any @x@, for all @y@ such that @y \`precedes\` x@,
-- it must be the case that @y@ occurs within some finite prefix
-- of @enumDownFrom x@.
--
-- We require that 'precedes' forms a strict partial order. That
-- is, it must obey the following laws (N.B., if the first two laws
-- hold, then the third one follows for free):
--
-- > if x `precedes` y && y `precedes` z then x `precedes` z
-- > if x `precedes` y then not (y `precedes` x)
-- > not (x `precedes` x)
--
-- Moreover, we require that 'precedes' agrees with 'pred', and
-- that 'pred' is exhaustive for 'precedes' (assuming @Eq a@, by
-- magic if need be):
--
-- > if pred x == Just y then y `precedes` x
-- > if x `precedes` y   then x `elem` enumDownFrom y
--
-- Minimal complete definition: 'pred', 'precedes'.
class DownwardEnum a where

    -- | The predecessor of a value, or @Nothing@ is there isn't one.
    -- For the numeric types in the Prelude, 'pred' subtracts 1.
    pred :: a -> Maybe a

    -- | A variant of @('<')@ with regards to the enumeration order.
    precedes :: a -> a -> Bool

    -- well-founded ~ Artinian
    -- | Return @x@ followed by all it's predecessors, in (reverse)
    -- order. The resulting list is always non-empty, since it
    -- includes @x@. If the resulting list is always finite, then
    -- the 'precedes' ordering is well-founded. In GHC, the default
    -- implementation is a \"good producer\" for list fusion.
    enumDownFrom :: a -> [a]
#ifdef __GLASGOW_HASKELL__
    {-# INLINE enumDownFrom #-}
    enumDownFrom a
x0 = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (a -> (a -> b -> b) -> b -> b
forall t t. DownwardEnum t => t -> (t -> t -> t) -> t -> t
enumDownFromFB a
x0)
        where
        {-# INLINE [0] enumDownFromFB #-}
        enumDownFromFB :: t -> (t -> t -> t) -> t -> t
enumDownFromFB t
x t -> t -> t
cons t
nil = t
x t -> t -> t
`cons`
            case t -> Maybe t
forall a. DownwardEnum a => a -> Maybe a
pred t
x of
            Maybe t
Nothing -> t
nil
            Just t
y  -> t -> (t -> t -> t) -> t -> t
enumDownFromFB t
y t -> t -> t
cons t
nil
#else
    enumDownFrom x = x :
        case pred x of
        Nothing -> []
        Just y  -> enumDownFrom y
#endif

    -- | Return the elements of @'enumDownFrom' x@, filtering out
    -- everything that precedes @z@. If @x@ precedes @z@, then the
    -- resulting list is empty; otherwise, it is non-empty, since
    -- it includes @x@. In GHC, the default implementation is a
    -- \"good producer\" for list fusion.
    enumDownFromTo :: a -> a -> [a]
#ifdef __GLASGOW_HASKELL__
    {-# INLINE enumDownFromTo #-}
    enumDownFromTo a
x0 a
z0 = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (a -> a -> (a -> b -> b) -> b -> b
forall t t. DownwardEnum t => t -> t -> (t -> t -> t) -> t -> t
enumDownFromToFB a
x0 a
z0)
        where
        {-# INLINE [0] enumDownFromToFB #-}
        enumDownFromToFB :: t -> t -> (t -> t -> t) -> t -> t
enumDownFromToFB t
x t
z t -> t -> t
cons t
nil
            |  t
x t -> t -> Bool
forall a. DownwardEnum a => a -> a -> Bool
`precedes` t
z = t
nil
            | Bool
otherwise       = t
x t -> t -> t
`cons`
                case t -> Maybe t
forall a. DownwardEnum a => a -> Maybe a
pred t
x of
                Maybe t
Nothing -> t
nil
                Just t
y  -> t -> t -> (t -> t -> t) -> t -> t
enumDownFromToFB t
y t
z t -> t -> t
cons t
nil
#else
    enumDownFromTo x z
        |  x `precedes` z = []
        | otherwise       = x :
            case pred x of
            Nothing -> []
            Just y  -> enumDownFromTo y z
#endif

----------------------------------------------------------------
-- | A class for types with a linear enumeration order. We require
-- that the partial orders of the superclasses agree:
--
-- > x `succeeds` y  ==  y `precedes` x
--
-- That the enumeration order is preserved\/reflected:
--
-- > i `succeeds` j  ==  toEnum   i `succeeds` toEnum   j
-- > x `succeeds` y  ==  fromEnum x `succeeds` fromEnum y
--
-- And that 'toEnum' and 'fromEnum' form a weak isomorphism; i.e.,
-- for some @p@ and @q@, the following must hold:
--
-- > fromEnum <=< toEnum    ==  (\i -> if p i then Just i else Nothing)
-- > toEnum   <=< fromEnum  ==  (\x -> if q x then Just x else Nothing)
--
-- In other words, the following type-restricted functions form an
-- isomorphism of linear orderings.
--
-- > toEnum'   :: {i :: Int | toEnum   i == Just _} -> a
-- > fromEnum' :: {x :: a   | fromEnum x == Just _} -> Int
--
-- Minimal complete definition: 'toEnum', 'fromEnum'. N.B., the
-- default definitions for 'enumFromThen' and 'enumFromThenTo' only
-- make sense when the type @a@ is \"smaller\" than 'Int' (i.e.,
-- 'fromEnum' always succeeds); if 'fromEnum' ever fails, then you
-- must override the defaults in order to correctly infer the stride
-- for values which cannot be converted to 'Int'.
class (UpwardEnum a, DownwardEnum a) => Enum a where

    -- | Convert from an 'Int'.
    toEnum :: Int -> Maybe a

    -- | Convert to an 'Int'.
    fromEnum :: a -> Maybe Int


    -- | Enumerate values with an inferred stride. The resulting
    -- list is always non-empty, since it includes @x@. Naturally,
    -- this should agree with 'enumFrom' and 'enumDownFrom' (assuming
    -- @Eq a@, by magic if need be):
    --
    -- > if succ x == Just y then enumFromThen x y == enumFrom x
    -- > if pred x == Just y then enumFromThen x y == enumDownFrom x
    --
    -- In the default implementation: if 'fromEnum' fails on either
    -- argument, then the result is exactly @[x]@; and if 'toEnum'
    -- fails on any of the enumerated integers, then the first
    -- failure terminates the enumeration. If either of these
    -- properties is inappropriate, then you should override the
    -- default. In GHC, the default implementation is a \"good
    -- producer\" for list fusion.
    enumFromThen :: a -> a -> [a]
    enumFromThen a
x a
y =
        [a] -> ([a] -> [a]) -> Maybe [a] -> [a]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [a
x] [a] -> [a]
forall a. a -> a
id (Maybe [a] -> [a]) -> Maybe [a] -> [a]
forall a b. (a -> b) -> a -> b
$! do
            Int
x' <- a -> Maybe Int
forall a. Enum a => a -> Maybe Int
fromEnum a
x
            Int
y' <- a -> Maybe Int
forall a. Enum a => a -> Maybe Int
fromEnum a
y
            [a] -> Maybe [a]
forall (m :: * -> *) a. Monad m => a -> m a
return ([a] -> Maybe [a]) -> [a] -> Maybe [a]
forall a b. (a -> b) -> a -> b
$! [Int] -> [a]
forall a. Enum a => [Int] -> [a]
takeEnum (Int -> Int -> [Int]
forall a. Enum a => a -> a -> [a]
enumFromThen Int
x' Int
y')


    -- | Enumerate values with an inferred stride and a given limit.
    -- If @x@ precedes @y@ (and therefore we're enumerating forward)
    -- but @x@ succeeds @z@ (and therefore is past the limit), then
    -- the result is empty. Similarly, if @x@ succeeds @y@ (and
    -- therefore we're enumerating backward) but @x@ precedes @z@
    -- (and therefore is past the limit), then the result is empty.
    -- Otherwise the result is non-empty since it contains @x@.
    -- Naturally, this should agree with 'enumFromTo' and
    -- 'enumDownFromTo' (assuming @Eq a@, by magic if need be):
    --
    -- > if succ x == Just y then enumFromThenTo x y z == enumFromTo x z
    -- > if pred x == Just y then enumFromThenTo x y z == enumDownFromTo x z
    --
    -- In the default implementation: if 'fromEnum' fails on any
    -- argument, then the result is either @[]@ or @[x]@ (as
    -- appropriate); and if 'toEnum' fails on any of the enumerated
    -- integers, then the first failure terminates the enumeration.
    -- If either of these properties is inappropriate, then you
    -- should override the default. In GHC, the default implementation
    -- is a \"good producer\" for list fusion.
    enumFromThenTo :: a -> a -> a -> [a]
    enumFromThenTo a
x a
y a
z
        | a
x a -> a -> Bool
forall a. DownwardEnum a => a -> a -> Bool
`precedes` a
y Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. UpwardEnum a => a -> a -> Bool
`succeeds` a
z = []
        | a
x a -> a -> Bool
forall a. UpwardEnum a => a -> a -> Bool
`succeeds` a
y Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. DownwardEnum a => a -> a -> Bool
`precedes` a
z = []
        | Bool
otherwise =
            [a] -> ([a] -> [a]) -> Maybe [a] -> [a]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [a
x] [a] -> [a]
forall a. a -> a
id (Maybe [a] -> [a]) -> Maybe [a] -> [a]
forall a b. (a -> b) -> a -> b
$! do
                Int
x' <- a -> Maybe Int
forall a. Enum a => a -> Maybe Int
fromEnum a
x
                Int
y' <- a -> Maybe Int
forall a. Enum a => a -> Maybe Int
fromEnum a
y
                Int
z' <- a -> Maybe Int
forall a. Enum a => a -> Maybe Int
fromEnum a
z
                [a] -> Maybe [a]
forall (m :: * -> *) a. Monad m => a -> m a
return ([a] -> Maybe [a]) -> [a] -> Maybe [a]
forall a b. (a -> b) -> a -> b
$! [Int] -> [a]
forall a. Enum a => [Int] -> [a]
takeEnum (Int -> Int -> Int -> [Int]
forall a. Enum a => a -> a -> a -> [a]
enumFromThenTo Int
x' Int
y' Int
z')


-- | Convert the integers via 'toEnum', and keep taking the results
-- until the first @Nothing@. In GHC, this is both a \"good producer\"
-- and a \"good consumer\" for list fusion.
takeEnum :: Enum a => [Int] -> [a]
#ifdef __GLASGOW_HASKELL__
{-# INLINE takeEnum #-}
takeEnum :: [Int] -> [a]
takeEnum [Int]
xs0 = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\a -> b -> b
cons b
nil -> (Int -> b -> b) -> b -> [Int] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((a -> b -> b) -> b -> Int -> b -> b
forall t t p. Enum t => (t -> t -> p) -> p -> Int -> t -> p
takeEnumCons a -> b -> b
cons b
nil) b
nil [Int]
xs0)
    where
    {-# INLINE takeEnumCons #-}
    takeEnumCons :: (t -> t -> p) -> p -> Int -> t -> p
takeEnumCons t -> t -> p
cons p
nil Int
x t
ys =
        case Int -> Maybe t
forall a. Enum a => Int -> Maybe a
toEnum Int
x of
        Maybe t
Nothing -> p
nil
        Just t
y  -> t
y t -> t -> p
`cons` t
ys
#else
takeEnum []     = []
takeEnum (x:xs) =
    case toEnum x of
    Nothing -> []
    Just y  -> y : takeEnum xs
#endif

----------------------------------------------------------------
----------------------------------------------------------------
----- Inherited instances from the Prelude

preludeEnumDownFrom :: (DownwardEnum a, Prelude.Enum a) => a -> [a]
preludeEnumDownFrom :: a -> [a]
preludeEnumDownFrom a
x =
    case a -> Maybe a
forall a. DownwardEnum a => a -> Maybe a
pred a
x of
    Maybe a
Nothing -> [a
x]
    Just a
y  -> a -> a -> [a]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromThen a
x a
y
{-# INLINE preludeEnumDownFrom #-}


preludeEnumDownFromTo :: (DownwardEnum a, Prelude.Enum a) => a -> a -> [a]
preludeEnumDownFromTo :: a -> a -> [a]
preludeEnumDownFromTo a
x a
z =
    case a -> Maybe a
forall a. DownwardEnum a => a -> Maybe a
pred a
x of
    Maybe a
Nothing -> [a
x]
    Just a
y  -> a -> a -> a -> [a]
forall a. Enum a => a -> a -> a -> [a]
Prelude.enumFromThenTo a
x a
y a
z
{-# INLINE preludeEnumDownFromTo #-}


instance UpwardEnum () where
    succ :: () -> Maybe ()
succ ()    = Maybe ()
forall a. Maybe a
Nothing
    succeeds :: () -> () -> Bool
succeeds   = () -> () -> Bool
forall a. Ord a => a -> a -> Bool
(>)
    enumFrom :: () -> [()]
enumFrom   = () -> [()]
forall a. Enum a => a -> [a]
Prelude.enumFrom
    enumFromTo :: () -> () -> [()]
enumFromTo = () -> () -> [()]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum () where
    pred :: () -> Maybe ()
pred ()        = Maybe ()
forall a. Maybe a
Nothing
    precedes :: () -> () -> Bool
precedes       = () -> () -> Bool
forall a. Ord a => a -> a -> Bool
(<)
    enumDownFrom :: () -> [()]
enumDownFrom   = () -> [()]
forall a. (DownwardEnum a, Enum a) => a -> [a]
preludeEnumDownFrom
    enumDownFromTo :: () -> () -> [()]
enumDownFromTo = () -> () -> [()]
forall a. (DownwardEnum a, Enum a) => a -> a -> [a]
preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum () where
    toEnum :: Int -> Maybe ()
toEnum Int
i
        | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0    = () -> Maybe ()
forall a. a -> Maybe a
Just ()
        | Bool
otherwise = Maybe ()
forall a. Maybe a
Nothing
    fromEnum :: () -> Maybe Int
fromEnum ()     = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0
    enumFromThen :: () -> () -> [()]
enumFromThen    = () -> () -> [()]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromThen
    enumFromThenTo :: () -> () -> () -> [()]
enumFromThenTo  = () -> () -> () -> [()]
forall a. Enum a => a -> a -> a -> [a]
Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}

----------------------------------------------------------------
instance UpwardEnum Bool where
    succ :: Bool -> Maybe Bool
succ Bool
False = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
    succ Bool
True  = Maybe Bool
forall a. Maybe a
Nothing
    succeeds :: Bool -> Bool -> Bool
succeeds   = Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
(>)
    enumFrom :: Bool -> [Bool]
enumFrom   = Bool -> [Bool]
forall a. Enum a => a -> [a]
Prelude.enumFrom
    enumFromTo :: Bool -> Bool -> [Bool]
enumFromTo = Bool -> Bool -> [Bool]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum Bool where
    pred :: Bool -> Maybe Bool
pred Bool
True      = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
    pred Bool
False     = Maybe Bool
forall a. Maybe a
Nothing
    precedes :: Bool -> Bool -> Bool
precedes       = Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
(<)
    enumDownFrom :: Bool -> [Bool]
enumDownFrom   = Bool -> [Bool]
forall a. (DownwardEnum a, Enum a) => a -> [a]
preludeEnumDownFrom
    enumDownFromTo :: Bool -> Bool -> [Bool]
enumDownFromTo = Bool -> Bool -> [Bool]
forall a. (DownwardEnum a, Enum a) => a -> a -> [a]
preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum Bool where
    toEnum :: Int -> Maybe Bool
toEnum Int
i
        | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0    = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
        | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1    = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
        | Bool
otherwise = Maybe Bool
forall a. Maybe a
Nothing
    fromEnum :: Bool -> Maybe Int
fromEnum Bool
False  = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0
    fromEnum Bool
True   = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
1
    enumFromThen :: Bool -> Bool -> [Bool]
enumFromThen    = Bool -> Bool -> [Bool]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromThen
    enumFromThenTo :: Bool -> Bool -> Bool -> [Bool]
enumFromThenTo  = Bool -> Bool -> Bool -> [Bool]
forall a. Enum a => a -> a -> a -> [a]
Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}

----------------------------------------------------------------
instance UpwardEnum Ordering where
    succ :: Ordering -> Maybe Ordering
succ Ordering
LT    = Ordering -> Maybe Ordering
forall a. a -> Maybe a
Just Ordering
EQ
    succ Ordering
EQ    = Ordering -> Maybe Ordering
forall a. a -> Maybe a
Just Ordering
GT
    succ Ordering
GT    = Maybe Ordering
forall a. Maybe a
Nothing
    succeeds :: Ordering -> Ordering -> Bool
succeeds   = Ordering -> Ordering -> Bool
forall a. Ord a => a -> a -> Bool
(>)
    enumFrom :: Ordering -> [Ordering]
enumFrom   = Ordering -> [Ordering]
forall a. Enum a => a -> [a]
Prelude.enumFrom
    enumFromTo :: Ordering -> Ordering -> [Ordering]
enumFromTo = Ordering -> Ordering -> [Ordering]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum Ordering where
    pred :: Ordering -> Maybe Ordering
pred Ordering
GT        = Ordering -> Maybe Ordering
forall a. a -> Maybe a
Just Ordering
EQ
    pred Ordering
EQ        = Ordering -> Maybe Ordering
forall a. a -> Maybe a
Just Ordering
LT
    pred Ordering
LT        = Maybe Ordering
forall a. Maybe a
Nothing
    precedes :: Ordering -> Ordering -> Bool
precedes       = Ordering -> Ordering -> Bool
forall a. Ord a => a -> a -> Bool
(<)
    enumDownFrom :: Ordering -> [Ordering]
enumDownFrom   = Ordering -> [Ordering]
forall a. (DownwardEnum a, Enum a) => a -> [a]
preludeEnumDownFrom
    enumDownFromTo :: Ordering -> Ordering -> [Ordering]
enumDownFromTo = Ordering -> Ordering -> [Ordering]
forall a. (DownwardEnum a, Enum a) => a -> a -> [a]
preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum Ordering where
    toEnum :: Int -> Maybe Ordering
toEnum Int
i
        | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0    = Ordering -> Maybe Ordering
forall a. a -> Maybe a
Just Ordering
LT
        | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1    = Ordering -> Maybe Ordering
forall a. a -> Maybe a
Just Ordering
EQ
        | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2    = Ordering -> Maybe Ordering
forall a. a -> Maybe a
Just Ordering
GT
        | Bool
otherwise = Maybe Ordering
forall a. Maybe a
Nothing
    fromEnum :: Ordering -> Maybe Int
fromEnum Ordering
LT     = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0
    fromEnum Ordering
EQ     = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
1
    fromEnum Ordering
GT     = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
2
    enumFromThen :: Ordering -> Ordering -> [Ordering]
enumFromThen    = Ordering -> Ordering -> [Ordering]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromThen
    enumFromThenTo :: Ordering -> Ordering -> Ordering -> [Ordering]
enumFromThenTo  = Ordering -> Ordering -> Ordering -> [Ordering]
forall a. Enum a => a -> a -> a -> [a]
Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}

----------------------------------------------------------------
instance UpwardEnum Char where
#if __GLASGOW_HASKELL__ >= 708
    succ :: Char -> Maybe Char
succ (C# Char#
c#)
        | Int# -> Bool
isTrue# (Char# -> Int#
ord# Char#
c# Int# -> Int# -> Int#
/=# Int#
0x10FFFF#)
                    = Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char) -> Char -> Maybe Char
forall a b. (a -> b) -> a -> b
$! Char# -> Char
C# (Int# -> Char#
chr# (Char# -> Int#
ord# Char#
c# Int# -> Int# -> Int#
+# Int#
1#))
        | Bool
otherwise = Maybe Char
forall a. Maybe a
Nothing
#elif defined __GLASGOW_HASKELL__
    succ (C# c#)
        | not (ord# c# ==# 0x10FFFF#) = Just $! C# (chr# (ord# c# +# 1#))
        | otherwise                   = Nothing
#else
    succ c
        | not (ord c == 0x10FFFF) = Just $! chr (ord c + 1)
        | otherwise               = Nothing
#endif
    succeeds :: Char -> Char -> Bool
succeeds   = Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
(>)
    enumFrom :: Char -> [Char]
enumFrom   = Char -> [Char]
forall a. Enum a => a -> [a]
Prelude.enumFrom
    enumFromTo :: Char -> Char -> [Char]
enumFromTo = Char -> Char -> [Char]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum Char where
#if __GLASGOW_HASKELL__ >= 708
    pred :: Char -> Maybe Char
pred (C# Char#
c#)
        | Int# -> Bool
isTrue# (Char# -> Int#
ord# Char#
c# Int# -> Int# -> Int#
/=# Int#
0#)
                    = Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char) -> Char -> Maybe Char
forall a b. (a -> b) -> a -> b
$! Char# -> Char
C# (Int# -> Char#
chr# (Char# -> Int#
ord# Char#
c# Int# -> Int# -> Int#
-# Int#
1#))
        | Bool
otherwise = Maybe Char
forall a. Maybe a
Nothing
#elif defined __GLASGOW_HASKELL__
    pred (C# c#)
        | not (ord# c# ==# 0#) = Just $! C# (chr# (ord# c# -# 1#))
        | otherwise            = Nothing
#else
    pred c
        | not (ord c == 0) = Just $! chr (ord c - 1)
        | otherwise        = Nothing
#endif
    precedes :: Char -> Char -> Bool
precedes       = Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
(<)
    enumDownFrom :: Char -> [Char]
enumDownFrom   = Char -> [Char]
forall a. (DownwardEnum a, Enum a) => a -> [a]
preludeEnumDownFrom
    enumDownFromTo :: Char -> Char -> [Char]
enumDownFromTo = Char -> Char -> [Char]
forall a. (DownwardEnum a, Enum a) => a -> a -> [a]
preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum Char where
#if __GLASGOW_HASKELL__ >= 708
    toEnum :: Int -> Maybe Char
toEnum (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
0# Int# -> Int# -> Int#
<=# Int#
i#)
            Bool -> Bool -> Bool
&& Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
<=# Int#
0x10FFFF#) = Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char) -> Char -> Maybe Char
forall a b. (a -> b) -> a -> b
$! Char# -> Char
C# (Int# -> Char#
chr# Int#
i#)
        | Bool
otherwise                       = Maybe Char
forall a. Maybe a
Nothing
    fromEnum :: Char -> Maybe Int
fromEnum (C# Char#
c#)
        | Int# -> Bool
isTrue# (Char# -> Char# -> Int#
leChar# (Int# -> Char#
chr# Int#
0#) Char#
c#)
            Bool -> Bool -> Bool
&& Int# -> Bool
isTrue# (Char# -> Char# -> Int#
leChar# Char#
c# (Int# -> Char#
chr# Int#
0x10FFFF#)) = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$! Int# -> Int
I# (Char# -> Int#
ord# Char#
c#)
        | Bool
otherwise                                  = Maybe Int
forall a. Maybe a
Nothing
#elif defined __GLASGOW_HASKELL__
    toEnum (I# i#)
        | 0# <=# i# && i# <=# 0x10FFFF# = Just $! C# (chr# i#)
        | otherwise                     = Nothing
    fromEnum (C# c#)
        | leChar# (chr# 0#) c#
            && leChar# c# (chr# 0x10FFFF#) = Just $! I# (ord# c#)
        | otherwise                        = Nothing
#else
    toEnum i
        | 0 <= i && i <= 0x10FFFF = Just $! chr i
        | otherwise               = Nothing
    fromEnum c
        | chr 0 <= c && c <= chr 0x10FFFF = Just $! ord c
        | otherwise                       = Nothing
#endif
    enumFromThen :: Char -> Char -> [Char]
enumFromThen   = Char -> Char -> [Char]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromThen
    enumFromThenTo :: Char -> Char -> Char -> [Char]
enumFromThenTo = Char -> Char -> Char -> [Char]
forall a. Enum a => a -> a -> a -> [a]
Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}

----------------------------------------------------------------
instance UpwardEnum Int where
    succ :: Int -> Maybe Int
succ Int
x
        | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Bounded a => a
maxBound = Maybe Int
forall a. Maybe a
Nothing
        | Bool
otherwise     = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$! Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
    succeeds :: Int -> Int -> Bool
succeeds   = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>)
    enumFrom :: Int -> [Int]
enumFrom   = Int -> [Int]
forall a. Enum a => a -> [a]
Prelude.enumFrom
    enumFromTo :: Int -> Int -> [Int]
enumFromTo = Int -> Int -> [Int]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum Int where
    pred :: Int -> Maybe Int
pred Int
x
        | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Bounded a => a
minBound = Maybe Int
forall a. Maybe a
Nothing
        | Bool
otherwise     = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$! Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
    precedes :: Int -> Int -> Bool
precedes       = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<)
    enumDownFrom :: Int -> [Int]
enumDownFrom   = Int -> [Int]
forall a. (DownwardEnum a, Enum a) => a -> [a]
preludeEnumDownFrom
    enumDownFromTo :: Int -> Int -> [Int]
enumDownFromTo = Int -> Int -> [Int]
forall a. (DownwardEnum a, Enum a) => a -> a -> [a]
preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum Int where
    toEnum :: Int -> Maybe Int
toEnum         = Int -> Maybe Int
forall a. a -> Maybe a
Just
    fromEnum :: Int -> Maybe Int
fromEnum       = Int -> Maybe Int
forall a. a -> Maybe a
Just
    enumFromThen :: Int -> Int -> [Int]
enumFromThen   = Int -> Int -> [Int]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromThen
    enumFromThenTo :: Int -> Int -> Int -> [Int]
enumFromThenTo = Int -> Int -> Int -> [Int]
forall a. Enum a => a -> a -> a -> [a]
Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}

----------------------------------------------------------------
-- TODO: instances for Int8, Int16, Int32, Int64

----------------------------------------------------------------
-- TODO: instances for Word, Word8, Word16, Word32, Word64

----------------------------------------------------------------
instance UpwardEnum Integer where
    succ :: Integer -> Maybe Integer
succ Integer
n     = Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Integer -> Maybe Integer) -> Integer -> Maybe Integer
forall a b. (a -> b) -> a -> b
$! Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
1
    succeeds :: Integer -> Integer -> Bool
succeeds   = Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
(>)
    enumFrom :: Integer -> [Integer]
enumFrom   = Integer -> [Integer]
forall a. Enum a => a -> [a]
Prelude.enumFrom
    enumFromTo :: Integer -> Integer -> [Integer]
enumFromTo = Integer -> Integer -> [Integer]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum Integer where
    pred :: Integer -> Maybe Integer
pred Integer
n         = Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Integer -> Maybe Integer) -> Integer -> Maybe Integer
forall a b. (a -> b) -> a -> b
$! Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
1
    precedes :: Integer -> Integer -> Bool
precedes       = Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
(<)
    enumDownFrom :: Integer -> [Integer]
enumDownFrom   = Integer -> [Integer]
forall a. (DownwardEnum a, Enum a) => a -> [a]
preludeEnumDownFrom
    enumDownFromTo :: Integer -> Integer -> [Integer]
enumDownFromTo = Integer -> Integer -> [Integer]
forall a. (DownwardEnum a, Enum a) => a -> a -> [a]
preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum Integer where
    toEnum :: Int -> Maybe Integer
toEnum   Int
n = Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Integer -> Maybe Integer) -> Integer -> Maybe Integer
forall a b. (a -> b) -> a -> b
$! Int -> Integer
forall a. Enum a => Int -> a
Prelude.toEnum Int
n
    fromEnum :: Integer -> Maybe Int
fromEnum Integer
n
        | Integer
min_ Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
n Bool -> Bool -> Bool
&& Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
max_ = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$! Integer -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Integer
n
        | Bool
otherwise              = Maybe Int
forall a. Maybe a
Nothing
        where
        min_ :: Integer
min_ = Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
forall a. Bounded a => a
minBound :: Int)
        max_ :: Integer
max_ = Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
forall a. Bounded a => a
maxBound :: Int)
    enumFromThen :: Integer -> Integer -> [Integer]
enumFromThen   = Integer -> Integer -> [Integer]
forall a. Enum a => a -> a -> [a]
Prelude.enumFromThen
    enumFromThenTo :: Integer -> Integer -> Integer -> [Integer]
enumFromThenTo = Integer -> Integer -> Integer -> [Integer]
forall a. Enum a => a -> a -> a -> [a]
Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}

----------------------------------------------------------------
{-
-- The 'succ'\/'pred' functions are not complete for 'succeeds'\/'precedes'

instance UpwardEnum Float where
    succ n     = Just $! n + 1
    succeeds   = (>)
    enumFrom   = Prelude.enumFrom
    enumFromTo = Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum Float where
    pred n         = Just $! n - 1
    precedes       = (<)
    enumDownFrom   = preludeEnumDownFrom
    enumDownFromTo = preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum Float where
    toEnum   n     = Just $! Prelude.toEnum   n -- Does int2Float ever error?
    fromEnum n     = Just $! Prelude.fromEnum n -- Does fromInteger . truncate?
    enumFromThen   = Prelude.enumFromThen
    enumFromThenTo = Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}

----------------------------------------------------------------
instance UpwardEnum Double where
    succ n     = Just $! n + 1
    succeeds   = (>)
    enumFrom   = Prelude.enumFrom
    enumFromTo = Prelude.enumFromTo
    {-# INLINE succ #-}
    {-# INLINE succeeds #-}
    {-# INLINE enumFrom #-}
    {-# INLINE enumFromTo #-}

instance DownwardEnum Double where
    pred n         = Just $! n - 1
    precedes       = (<)
    enumDownFrom   = preludeEnumDownFrom
    enumDownFromTo = preludeEnumDownFromTo
    {-# INLINE pred #-}
    {-# INLINE precedes #-}
    {-# INLINE enumDownFrom #-}
    {-# INLINE enumDownFromTo #-}

instance Enum Double where
    toEnum   n     = Just $! Prelude.toEnum   n -- Does int2Double ever error?
    fromEnum n     = Just $! Prelude.fromEnum n -- Does fromInteger . truncate?
    enumFromThen   = Prelude.enumFromThen
    enumFromThenTo = Prelude.enumFromThenTo
    {-# INLINE toEnum #-}
    {-# INLINE fromEnum #-}
    {-# INLINE enumFromThen #-}
    {-# INLINE enumFromThenTo #-}
-}


----------------------------------------------------------------
-- TODO: the following (as appropriate)
{-
instance Enum (Data.Fixed.Fixed a)

instance Enum System.IO.IOMode
instance Enum GHC.IO.Device.SeekMode
instance Enum Foreign.C.Types.CUIntMax
instance Enum Foreign.C.Types.CIntMax
instance Enum Foreign.C.Types.CUIntPtr
instance Enum Foreign.C.Types.CIntPtr
instance Enum Foreign.C.Types.CSUSeconds
instance Enum Foreign.C.Types.CUSeconds
instance Enum Foreign.C.Types.CTime
instance Enum Foreign.C.Types.CClock
instance Enum Foreign.C.Types.CSigAtomic
instance Enum Foreign.C.Types.CWchar
instance Enum Foreign.C.Types.CSize
instance Enum Foreign.C.Types.CPtrdiff
instance Enum Foreign.C.Types.CDouble
instance Enum Foreign.C.Types.CFloat
instance Enum Foreign.C.Types.CULLong
instance Enum Foreign.C.Types.CLLong
instance Enum Foreign.C.Types.CULong
instance Enum Foreign.C.Types.CLong
instance Enum Foreign.C.Types.CUInt
instance Enum Foreign.C.Types.CInt
instance Enum Foreign.C.Types.CUShort
instance Enum Foreign.C.Types.CShort
instance Enum Foreign.C.Types.CUChar
instance Enum Foreign.C.Types.CSChar
instance Enum Foreign.C.Types.CChar
instance Enum Data.Char.GeneralCategory
instance Enum Foreign.Ptr.IntPtr
instance Enum Foreign.Ptr.WordPtr
instance Enum System.Posix.Types.Fd
instance Enum System.Posix.Types.CRLim
instance Enum System.Posix.Types.CTcflag
instance Enum System.Posix.Types.CSpeed
instance Enum System.Posix.Types.CCc
instance Enum System.Posix.Types.CUid
instance Enum System.Posix.Types.CNlink
instance Enum System.Posix.Types.CGid
instance Enum System.Posix.Types.CSsize
instance Enum System.Posix.Types.CPid
instance Enum System.Posix.Types.COff
instance Enum System.Posix.Types.CMode
instance Enum System.Posix.Types.CIno
instance Enum System.Posix.Types.CDev
-}

----------------------------------------------------------------
----------------------------------------------------------- fin.