(original) (raw)
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE Trustworthy #-} {-# OPTIONS_HADDOCK hide #-}
#include "MachDeps.h"
module GHC.Enum( Bounded(..), Enum(..), boundedEnumFrom, boundedEnumFromThen, toEnumError, fromEnumError, succError, predError,
) where
import GHC.Base hiding ( many ) import GHC.Char import GHC.Integer import GHC.Num import GHC.Show default ()
class Bounded a where minBound, maxBound :: a
[succ](GHC.Enum.html#succ) :: [a](#local-6989586621679038252) -> [a](#local-6989586621679038252)
[pred](GHC.Enum.html#pred) :: [a](#local-6989586621679038252) -> [a](#local-6989586621679038252)
[toEnum](GHC.Enum.html#toEnum) :: Int -> [a](#local-6989586621679038252)
[fromEnum](GHC.Enum.html#fromEnum) :: [a](#local-6989586621679038252) -> Int
[enumFrom](GHC.Enum.html#enumFrom) :: [a](#local-6989586621679038252) -> [[a](#local-6989586621679038252)]
[enumFromThen](GHC.Enum.html#enumFromThen) :: [a](#local-6989586621679038252) -> [a](#local-6989586621679038252) -> [[a](#local-6989586621679038252)]
[enumFromTo](GHC.Enum.html#enumFromTo) :: [a](#local-6989586621679038252) -> [a](#local-6989586621679038252) -> [[a](#local-6989586621679038252)]
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) :: [a](#local-6989586621679038252) -> [a](#local-6989586621679038252) -> [a](#local-6989586621679038252) -> [[a](#local-6989586621679038252)]
[succ](GHC.Enum.html#succ) = [toEnum](GHC.Enum.html#toEnum) [.](GHC.Base.html#.) ([+](GHC.Num.html#%2B) 1) [.](GHC.Base.html#.) [fromEnum](GHC.Enum.html#fromEnum)
[pred](GHC.Enum.html#pred) = [toEnum](GHC.Enum.html#toEnum) [.](GHC.Base.html#.) ([subtract](GHC.Num.html#subtract) 1) [.](GHC.Base.html#.) [fromEnum](GHC.Enum.html#fromEnum)
[enumFrom](GHC.Enum.html#enumFrom) [x](#local-6989586621679038253) = [map](GHC.Base.html#map) [toEnum](GHC.Enum.html#toEnum) [[fromEnum](GHC.Enum.html#fromEnum) [x](#local-6989586621679038253) ..]
[enumFromThen](GHC.Enum.html#enumFromThen) [x](#local-6989586621679038254) [y](#local-6989586621679038255) = [map](GHC.Base.html#map) [toEnum](GHC.Enum.html#toEnum) [[fromEnum](GHC.Enum.html#fromEnum) [x](#local-6989586621679038254), [fromEnum](GHC.Enum.html#fromEnum) [y](#local-6989586621679038255) ..]
[enumFromTo](GHC.Enum.html#enumFromTo) [x](#local-6989586621679038256) [y](#local-6989586621679038257) = [map](GHC.Base.html#map) [toEnum](GHC.Enum.html#toEnum) [[fromEnum](GHC.Enum.html#fromEnum) [x](#local-6989586621679038256) .. [fromEnum](GHC.Enum.html#fromEnum) [y](#local-6989586621679038257)]
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) [x1](#local-6989586621679038258) [x2](#local-6989586621679038259) [y](#local-6989586621679038260) = [map](GHC.Base.html#map) [toEnum](GHC.Enum.html#toEnum) [[fromEnum](GHC.Enum.html#fromEnum) [x1](#local-6989586621679038258), [fromEnum](GHC.Enum.html#fromEnum) [x2](#local-6989586621679038259) .. [fromEnum](GHC.Enum.html#fromEnum) [y](#local-6989586621679038260)]
boundedEnumFrom :: (Enum a, Bounded a) => a -> [a]
boundedEnumFrom n = map toEnum [fromEnum n .. fromEnum (maxBound [asTypeOf](GHC.Base.html#asTypeOf)
n)]
boundedEnumFromThen :: (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen n1 n2
| i_n2 >= i_n1 = map toEnum [i_n1, i_n2 .. fromEnum (maxBound [asTypeOf](GHC.Base.html#asTypeOf)
n1)]
| otherwise = map toEnum [i_n1, i_n2 .. fromEnum (minBound [asTypeOf](GHC.Base.html#asTypeOf)
n1)]
where
i_n1 = fromEnum n1
i_n2 = fromEnum n2
{-# NOINLINE toEnumError #-} toEnumError :: (Show a) => String -> Int -> (a,a) -> b toEnumError inst_ty i bnds = errorWithoutStackTrace $ "Enum.toEnum{" ++ inst_ty ++ "}: tag (" ++ show i ++ ") is outside of bounds " ++ show bnds
{-# NOINLINE fromEnumError #-} fromEnumError :: (Show a) => String -> a -> b fromEnumError inst_ty x = errorWithoutStackTrace $ "Enum.fromEnum{" ++ inst_ty ++ "}: value (" ++ show x ++ ") is outside of Int's bounds " ++ show (minBound::Int, maxBound::Int)
{-# NOINLINE succError #-} succError :: String -> a succError inst_ty = errorWithoutStackTrace $ "Enum.succ{" ++ inst_ty ++ "}: tried to take `succ' of maxBound"
{-# NOINLINE predError #-} predError :: String -> a predError inst_ty = errorWithoutStackTrace $ "Enum.pred{" ++ inst_ty ++ "}: tried to take `pred' of minBound"
deriving instance Bounded ()
instance Enum () where succ _ = errorWithoutStackTrace "Prelude.Enum.().succ: bad argument" pred _ = errorWithoutStackTrace "Prelude.Enum.().pred: bad argument"
[toEnum](GHC.Enum.html#toEnum) [x](#local-6989586621679038327) | [x](#local-6989586621679038327) == 0 = ()
| [otherwise](GHC.Base.html#otherwise) = [errorWithoutStackTrace](GHC.Err.html#errorWithoutStackTrace) "Prelude.Enum.().toEnum: bad argument"
[fromEnum](GHC.Enum.html#fromEnum) () = 0
[enumFrom](GHC.Enum.html#enumFrom) () = [()]
[enumFromThen](GHC.Enum.html#enumFromThen) () () = let [many](#local-6989586621679038328) = ():[many](#local-6989586621679038328) in [many](#local-6989586621679038328)
[enumFromTo](GHC.Enum.html#enumFromTo) () () = [()]
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) () () () = let [many](#local-6989586621679038329) = ():[many](#local-6989586621679038329) in [many](#local-6989586621679038329)
deriving instance (Bounded a, Bounded b) => Bounded (a,b)
deriving instance (Bounded a, Bounded b, Bounded c) => Bounded (a,b,c)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a,b,c,d)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a,b,c,d,e)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded (a,b,c,d,e,f)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g) => Bounded (a,b,c,d,e,f,g)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h) => Bounded (a,b,c,d,e,f,g,h)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i) => Bounded (a,b,c,d,e,f,g,h,i)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j) => Bounded (a,b,c,d,e,f,g,h,i,j)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k) => Bounded (a,b,c,d,e,f,g,h,i,j,k)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l) => Bounded (a,b,c,d,e,f,g,h,i,j,k,l)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m) => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n) => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n)
deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o) => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)
deriving instance Bounded Bool
instance Enum Bool where succ False = True succ True = errorWithoutStackTrace "Prelude.Enum.Bool.succ: bad argument"
pred True = False pred False = errorWithoutStackTrace "Prelude.Enum.Bool.pred: bad argument"
toEnum n | n == 0 = False | n == 1 = True | otherwise = errorWithoutStackTrace "Prelude.Enum.Bool.toEnum: bad argument"
fromEnum False = 0 fromEnum True = 1
enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen
deriving instance Bounded Ordering
instance Enum Ordering where succ LT = EQ succ EQ = GT succ GT = errorWithoutStackTrace "Prelude.Enum.Ordering.succ: bad argument"
pred GT = EQ pred EQ = LT pred LT = errorWithoutStackTrace "Prelude.Enum.Ordering.pred: bad argument"
toEnum n | n == 0 = LT | n == 1 = EQ | n == 2 = GT toEnum _ = errorWithoutStackTrace "Prelude.Enum.Ordering.toEnum: bad argument"
fromEnum LT = 0 fromEnum EQ = 1 fromEnum GT = 2
enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen
instance Bounded Char where minBound = '\0' maxBound = '\x10FFFF'
instance Enum Char where succ (C# c#) | isTrue# (ord# c# /=# 0x10FFFF#) = C# (chr# (ord# c# +# 1#)) | otherwise = errorWithoutStackTrace ("Prelude.Enum.Char.succ: bad argument") pred (C# c#) | isTrue# (ord# c# /=# 0#) = C# (chr# (ord# c# -# 1#)) | otherwise = errorWithoutStackTrace ("Prelude.Enum.Char.pred: bad argument")
[toEnum](GHC.Enum.html#toEnum) = [chr](GHC.Char.html#chr)
[fromEnum](GHC.Enum.html#fromEnum) = [ord](GHC.Base.html#ord)
{-# INLINE enumFrom #-}
[enumFrom](GHC.Enum.html#enumFrom) (C# [x](#local-6989586621679038317)) = [eftChar](GHC.Enum.html#eftChar) (ord# [x](#local-6989586621679038317)) 0x10FFFF#
{-# INLINE enumFromTo #-}
[enumFromTo](GHC.Enum.html#enumFromTo) (C# [x](#local-6989586621679038318)) (C# [y](#local-6989586621679038319)) = [eftChar](GHC.Enum.html#eftChar) (ord# [x](#local-6989586621679038318)) (ord# [y](#local-6989586621679038319))
{-# INLINE enumFromThen #-}
[enumFromThen](GHC.Enum.html#enumFromThen) (C# [x1](#local-6989586621679038320)) (C# [x2](#local-6989586621679038321)) = [efdChar](GHC.Enum.html#efdChar) (ord# [x1](#local-6989586621679038320)) (ord# [x2](#local-6989586621679038321))
{-# INLINE enumFromThenTo #-}
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) (C# [x1](#local-6989586621679038322)) (C# [x2](#local-6989586621679038323)) (C# [y](#local-6989586621679038324)) = [efdtChar](GHC.Enum.html#efdtChar) (ord# [x1](#local-6989586621679038322)) (ord# [x2](#local-6989586621679038323)) (ord# [y](#local-6989586621679038324))
{-# RULES
"eftChar" [1] forall x y. eftChar x y = build (\c n -> eftCharFB c n x y)
"efdChar" [1] forall x1 x2. efdChar x1 x2 = build (\ c n -> efdCharFB c n x1 x2)
"efdtChar" [~1] forall x1 x2 l. efdtChar x1 x2 l = build (\ c n -> efdtCharFB c n x1 x2 l)
"eftCharList" [1] eftCharFB (:) [] = eftChar
"efdCharList" [1] efdCharFB (:) [] = efdChar
"efdtCharList" [1] efdtCharFB (:) [] = efdtChar
#-}
{-# INLINE [0] eftCharFB #-}
eftCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> a
eftCharFB c n x0 y = go x0
where
go x | isTrue# (x ># y) = n
| otherwise = C# (chr# x) [c](#local-6989586621679038368)
go (x +# 1#)
{-# NOINLINE [1] eftChar #-} eftChar :: Int# -> Int# -> String eftChar x y | isTrue# (x ># y ) = [] | otherwise = C# (chr# x) : eftChar (x +# 1#) y
{-# INLINE [0] efdCharFB #-}
efdCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> a
efdCharFB c n x1 x2
| isTrue# (delta >=# 0#) = go_up_char_fb c n x1 delta 0x10FFFF#
| otherwise = go_dn_char_fb c n x1 delta 0#
where
= x2 -# x1
{-# NOINLINE [1] efdChar #-}
efdChar :: Int# -> Int# -> String
efdChar x1 x2
| isTrue# (delta >=# 0#) = go_up_char_list x1 delta 0x10FFFF#
| otherwise = go_dn_char_list x1 delta 0#
where
= x2 -# x1
{-# INLINE [0] efdtCharFB #-}
efdtCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a
efdtCharFB c n x1 x2 lim
| isTrue# (delta >=# 0#) = go_up_char_fb c n x1 delta lim
| otherwise = go_dn_char_fb c n x1 delta lim
where
= x2 -# x1
{-# NOINLINE [1] efdtChar #-}
efdtChar :: Int# -> Int# -> Int# -> String
efdtChar x1 x2 lim
| isTrue# (delta >=# 0#) = go_up_char_list x1 delta lim
| otherwise = go_dn_char_list x1 delta lim
where
= x2 -# x1
go_up_char_fb :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a
go_up_char_fb c n x0 delta lim
= go_up x0
where
go_up x | isTrue# (x ># lim) = n
| otherwise = C# (chr# x) [c](#local-6989586621679038394)
go_up (x +# delta)
go_dn_char_fb :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a
go_dn_char_fb c n x0 delta lim
= go_dn x0
where
go_dn x | isTrue# (x <# lim) = n
| otherwise = C# (chr# x) [c](#local-6989586621679038401)
go_dn (x +# delta)
go_up_char_list :: Int# -> Int# -> Int# -> String go_up_char_list x0 delta lim = go_up x0 where go_up x | isTrue# (x ># lim) = [] | otherwise = C# (chr# x) : go_up (x +# delta)
go_dn_char_list :: Int# -> Int# -> Int# -> String go_dn_char_list x0 delta lim = go_dn x0 where go_dn x | isTrue# (x <# lim) = [] | otherwise = C# (chr# x) : go_dn (x +# delta)
instance Bounded Int where minBound = minInt maxBound = maxInt
instance Enum Int where
succ x
| x == maxBound = errorWithoutStackTrace "Prelude.Enum.succ{Int}: tried to take succ' of maxBound" | [otherwise](GHC.Base.html#otherwise) = [x](#local-6989586621679038302) [+](GHC.Num.html#%2B) 1 [pred](GHC.Enum.html#pred) [x](#local-6989586621679038303) | [x](#local-6989586621679038303) == [minBound](GHC.Enum.html#minBound) = [errorWithoutStackTrace](GHC.Err.html#errorWithoutStackTrace) "Prelude.Enum.pred{Int}: tried to take
pred' of minBound"
| otherwise = x - 1
[toEnum](GHC.Enum.html#toEnum) [x](#local-6989586621679038304) = [x](#local-6989586621679038304)
[fromEnum](GHC.Enum.html#fromEnum) [x](#local-6989586621679038305) = [x](#local-6989586621679038305)
{-# INLINE enumFrom #-}
[enumFrom](GHC.Enum.html#enumFrom) (I# [x](#local-6989586621679038306)) = [eftInt](GHC.Enum.html#eftInt) [x](#local-6989586621679038306) [maxInt#](#local-6989586621679038307)
where !(I# [maxInt#](#local-6989586621679038307)) = [maxInt](GHC.Base.html#maxInt)
{-# INLINE enumFromTo #-}
[enumFromTo](GHC.Enum.html#enumFromTo) (I# [x](#local-6989586621679038308)) (I# [y](#local-6989586621679038309)) = [eftInt](GHC.Enum.html#eftInt) [x](#local-6989586621679038308) [y](#local-6989586621679038309)
{-# INLINE enumFromThen #-}
[enumFromThen](GHC.Enum.html#enumFromThen) (I# [x1](#local-6989586621679038310)) (I# [x2](#local-6989586621679038311)) = [efdInt](GHC.Enum.html#efdInt) [x1](#local-6989586621679038310) [x2](#local-6989586621679038311)
{-# INLINE enumFromThenTo #-}
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) (I# [x1](#local-6989586621679038312)) (I# [x2](#local-6989586621679038313)) (I# [y](#local-6989586621679038314)) = [efdtInt](GHC.Enum.html#efdtInt) [x1](#local-6989586621679038312) [x2](#local-6989586621679038313) [y](#local-6989586621679038314)
{-# RULES "eftInt" [~1] forall x y. eftInt x y = build (\ c n -> eftIntFB c n x y) "eftIntList" [1] eftIntFB (:) [] = eftInt #-}
{-# NOINLINE [1] eftInt #-} eftInt :: Int# -> Int# -> [Int]
eftInt x0 y | isTrue# (x0 ># y) = [] | otherwise = go x0 where go x = I# x : if isTrue# (x ==# y) then [] else go (x +# 1#)
{-# INLINE [0] eftIntFB #-}
eftIntFB :: (Int -> r -> r) -> r -> Int# -> Int# -> r
eftIntFB c n x0 y | isTrue# (x0 ># y) = n
| otherwise = go x0
where
go x = I# x [c](#local-6989586621679038422)
if isTrue# (x ==# y)
then n
else go (x +# 1#)
{-# RULES "efdtInt" [~1] forall x1 x2 y. efdtInt x1 x2 y = build (\ c n -> efdtIntFB c n x1 x2 y) "efdtIntUpList" [1] efdtIntFB (:) [] = efdtInt #-}
efdInt :: Int# -> Int# -> [Int]
efdInt x1 x2 | isTrue# (x2 >=# x1) = case maxInt of I# y -> efdtIntUp x1 x2 y | otherwise = case minInt of I# y -> efdtIntDn x1 x2 y
{-# NOINLINE [1] efdtInt #-} efdtInt :: Int# -> Int# -> Int# -> [Int]
efdtInt x1 x2 y | isTrue# (x2 >=# x1) = efdtIntUp x1 x2 y | otherwise = efdtIntDn x1 x2 y
{-# INLINE [0] efdtIntFB #-} efdtIntFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r efdtIntFB c n x1 x2 y | isTrue# (x2 >=# x1) = efdtIntUpFB c n x1 x2 y | otherwise = efdtIntDnFB c n x1 x2 y
efdtIntUp :: Int# -> Int# -> Int# -> [Int]
efdtIntUp x1 x2 y
| isTrue# (y <# x2) = if isTrue# (y <# x1) then [] else [I# x1]
| otherwise =
let = x2 -# x1
= y -# delta
[go_up](#local-6989586621679038445) [x](#local-6989586621679038446) | isTrue# ([x](#local-6989586621679038446) ># [y'](#local-6989586621679038444)) = [I# [x](#local-6989586621679038446)]
| [otherwise](GHC.Base.html#otherwise) = I# [x](#local-6989586621679038446) : [go_up](#local-6989586621679038445) ([x](#local-6989586621679038446) +# [delta](#local-6989586621679038443))
in I# [x1](#local-6989586621679038440) : [go_up](#local-6989586621679038445) [x2](#local-6989586621679038441)
{-# INLINE [0] efdtIntUpFB #-}
efdtIntUpFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r
efdtIntUpFB c n x1 x2 y
| isTrue# (y <# x2) = if isTrue# (y <# x1) then n else I# x1 [c](#local-6989586621679038447)
n
| otherwise =
let = x2 -# x1
= y -# delta
[go_up](#local-6989586621679038454) [x](#local-6989586621679038455) | isTrue# ([x](#local-6989586621679038455) ># [y'](#local-6989586621679038453)) = I# [x](#local-6989586621679038455) `[c](#local-6989586621679038447)` [n](#local-6989586621679038448)
| [otherwise](GHC.Base.html#otherwise) = I# [x](#local-6989586621679038455) `[c](#local-6989586621679038447)` [go_up](#local-6989586621679038454) ([x](#local-6989586621679038455) +# [delta](#local-6989586621679038452))
in I# [x1](#local-6989586621679038449) `[c](#local-6989586621679038447)` [go_up](#local-6989586621679038454) [x2](#local-6989586621679038450)
efdtIntDn :: Int# -> Int# -> Int# -> [Int]
efdtIntDn x1 x2 y
| isTrue# (y ># x2) = if isTrue# (y ># x1) then [] else [I# x1]
| otherwise =
let = x2 -# x1
= y -# delta
[go_dn](#local-6989586621679038461) [x](#local-6989586621679038462) | isTrue# ([x](#local-6989586621679038462) <# [y'](#local-6989586621679038460)) = [I# [x](#local-6989586621679038462)]
| [otherwise](GHC.Base.html#otherwise) = I# [x](#local-6989586621679038462) : [go_dn](#local-6989586621679038461) ([x](#local-6989586621679038462) +# [delta](#local-6989586621679038459))
{-# INLINE [0] efdtIntDnFB #-}
efdtIntDnFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r
efdtIntDnFB c n x1 x2 y
| isTrue# (y ># x2) = if isTrue# (y ># x1) then n else I# x1 [c](#local-6989586621679038463)
n
| otherwise =
let = x2 -# x1
= y -# delta
[go_dn](#local-6989586621679038470) [x](#local-6989586621679038471) | isTrue# ([x](#local-6989586621679038471) <# [y'](#local-6989586621679038469)) = I# [x](#local-6989586621679038471) `[c](#local-6989586621679038463)` [n](#local-6989586621679038464)
| [otherwise](GHC.Base.html#otherwise) = I# [x](#local-6989586621679038471) `[c](#local-6989586621679038463)` [go_dn](#local-6989586621679038470) ([x](#local-6989586621679038471) +# [delta](#local-6989586621679038468))
in I# [x1](#local-6989586621679038465) `[c](#local-6989586621679038463)` [go_dn](#local-6989586621679038470) [x2](#local-6989586621679038466)
instance Bounded Word where minBound = 0
#if WORD_SIZE_IN_BITS == 32 maxBound = W# (int2Word# 0xFFFFFFFF#) #elif WORD_SIZE_IN_BITS == 64 maxBound = W# (int2Word# 0xFFFFFFFFFFFFFFFF#) #else #error Unhandled value for WORD_SIZE_IN_BITS #endif
instance Enum Word where succ x | x /= maxBound = x + 1 | otherwise = succError "Word" pred x | x /= minBound = x - 1 | otherwise = predError "Word" toEnum i@(I# i#) | i >= 0 = W# (int2Word# i#) | otherwise = toEnumError "Word" i (minBound::Word, maxBound::Word) fromEnum x@(W# x#) | x <= maxIntWord = I# (word2Int# x#) | otherwise = fromEnumError "Word" x
{-# INLINE enumFrom #-}
[enumFrom](GHC.Enum.html#enumFrom) (W# [x#](#local-6989586621679038293)) = [eftWord](GHC.Enum.html#eftWord) [x#](#local-6989586621679038293) [maxWord#](#local-6989586621679038294)
where !(W# [maxWord#](#local-6989586621679038294)) = [maxBound](GHC.Enum.html#maxBound)
{-# INLINE enumFromTo #-}
[enumFromTo](GHC.Enum.html#enumFromTo) (W# [x](#local-6989586621679038295)) (W# [y](#local-6989586621679038296)) = [eftWord](GHC.Enum.html#eftWord) [x](#local-6989586621679038295) [y](#local-6989586621679038296)
{-# INLINE enumFromThen #-}
[enumFromThen](GHC.Enum.html#enumFromThen) (W# [x1](#local-6989586621679038297)) (W# [x2](#local-6989586621679038298)) = [efdWord](GHC.Enum.html#efdWord) [x1](#local-6989586621679038297) [x2](#local-6989586621679038298)
{-# INLINE enumFromThenTo #-}
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) (W# [x1](#local-6989586621679038299)) (W# [x2](#local-6989586621679038300)) (W# [y](#local-6989586621679038301)) = [efdtWord](GHC.Enum.html#efdtWord) [x1](#local-6989586621679038299) [x2](#local-6989586621679038300) [y](#local-6989586621679038301)
maxIntWord :: Word
maxIntWord = W# (case maxInt of I# i -> int2Word# i)
{-# RULES "eftWord" [~1] forall x y. eftWord x y = build (\ c n -> eftWordFB c n x y) "eftWordList" [1] eftWordFB (:) [] = eftWord #-}
{-# NOINLINE [1] eftWord #-} eftWord :: Word# -> Word# -> [Word]
eftWord x0 y | isTrue# (x0 gtWord#
y) = []
| otherwise = go x0
where
go x = W# x : if isTrue# (x eqWord#
y)
then []
else go (x plusWord#
1##)
{-# INLINE [0] eftWordFB #-}
eftWordFB :: (Word -> r -> r) -> r -> Word# -> Word# -> r
eftWordFB c n x0 y | isTrue# (x0 gtWord#
y) = n
| otherwise = go x0
where
go x = W# x [c](#local-6989586621679038477)
if isTrue# (x eqWord#
y)
then n
else go (x plusWord#
1##)
{-# RULES "efdtWord" [~1] forall x1 x2 y. efdtWord x1 x2 y = build (\ c n -> efdtWordFB c n x1 x2 y) "efdtWordUpList" [1] efdtWordFB (:) [] = efdtWord #-}
efdWord :: Word# -> Word# -> [Word]
efdWord x1 x2
| isTrue# (x2 geWord#
x1) = case maxBound of W# y -> efdtWordUp x1 x2 y
| otherwise = case minBound of W# y -> efdtWordDn x1 x2 y
{-# NOINLINE [1] efdtWord #-} efdtWord :: Word# -> Word# -> Word# -> [Word]
efdtWord x1 x2 y
| isTrue# (x2 geWord#
x1) = efdtWordUp x1 x2 y
| otherwise = efdtWordDn x1 x2 y
{-# INLINE [0] efdtWordFB #-}
efdtWordFB :: (Word -> r -> r) -> r -> Word# -> Word# -> Word# -> r
efdtWordFB c n x1 x2 y
| isTrue# (x2 geWord#
x1) = efdtWordUpFB c n x1 x2 y
| otherwise = efdtWordDnFB c n x1 x2 y
efdtWordUp :: Word# -> Word# -> Word# -> [Word]
efdtWordUp x1 x2 y
| isTrue# (y ltWord#
x2) = if isTrue# (y ltWord#
x1) then [] else [W# x1]
| otherwise =
let = x2
minusWord#
x1
= y
minusWord#
delta
[go_up](#local-6989586621679038500) [x](#local-6989586621679038501) | isTrue# ([x](#local-6989586621679038501) `gtWord#` [y'](#local-6989586621679038499)) = [W# [x](#local-6989586621679038501)]
| [otherwise](GHC.Base.html#otherwise) = W# [x](#local-6989586621679038501) : [go_up](#local-6989586621679038500) ([x](#local-6989586621679038501) `plusWord#` [delta](#local-6989586621679038498))
in W# [x1](#local-6989586621679038495) : [go_up](#local-6989586621679038500) [x2](#local-6989586621679038496)
{-# INLINE [0] efdtWordUpFB #-}
efdtWordUpFB :: (Word -> r -> r) -> r -> Word# -> Word# -> Word# -> r
efdtWordUpFB c n x1 x2 y
| isTrue# (y ltWord#
x2) = if isTrue# (y ltWord#
x1) then n else W# x1 [c](#local-6989586621679038502)
n
| otherwise =
let = x2
minusWord#
x1
= y
minusWord#
delta
[go_up](#local-6989586621679038509) [x](#local-6989586621679038510) | isTrue# ([x](#local-6989586621679038510) `gtWord#` [y'](#local-6989586621679038508)) = W# [x](#local-6989586621679038510) `[c](#local-6989586621679038502)` [n](#local-6989586621679038503)
| [otherwise](GHC.Base.html#otherwise) = W# [x](#local-6989586621679038510) `[c](#local-6989586621679038502)` [go_up](#local-6989586621679038509) ([x](#local-6989586621679038510) `plusWord#` [delta](#local-6989586621679038507))
in W# [x1](#local-6989586621679038504) `[c](#local-6989586621679038502)` [go_up](#local-6989586621679038509) [x2](#local-6989586621679038505)
efdtWordDn :: Word# -> Word# -> Word# -> [Word]
efdtWordDn x1 x2 y
| isTrue# (y gtWord#
x2) = if isTrue# (y gtWord#
x1) then [] else [W# x1]
| otherwise =
let = x2
minusWord#
x1
= y
minusWord#
delta
[go_dn](#local-6989586621679038516) [x](#local-6989586621679038517) | isTrue# ([x](#local-6989586621679038517) `ltWord#` [y'](#local-6989586621679038515)) = [W# [x](#local-6989586621679038517)]
| [otherwise](GHC.Base.html#otherwise) = W# [x](#local-6989586621679038517) : [go_dn](#local-6989586621679038516) ([x](#local-6989586621679038517) `plusWord#` [delta](#local-6989586621679038514))
{-# INLINE [0] efdtWordDnFB #-}
efdtWordDnFB :: (Word -> r -> r) -> r -> Word# -> Word# -> Word# -> r
efdtWordDnFB c n x1 x2 y
| isTrue# (y gtWord#
x2) = if isTrue# (y gtWord#
x1) then n else W# x1 [c](#local-6989586621679038518)
n
| otherwise =
let = x2
minusWord#
x1
= y
minusWord#
delta
[go_dn](#local-6989586621679038525) [x](#local-6989586621679038526) | isTrue# ([x](#local-6989586621679038526) `ltWord#` [y'](#local-6989586621679038524)) = W# [x](#local-6989586621679038526) `[c](#local-6989586621679038518)` [n](#local-6989586621679038519)
| [otherwise](GHC.Base.html#otherwise) = W# [x](#local-6989586621679038526) `[c](#local-6989586621679038518)` [go_dn](#local-6989586621679038525) ([x](#local-6989586621679038526) `plusWord#` [delta](#local-6989586621679038523))
in W# [x1](#local-6989586621679038520) `[c](#local-6989586621679038518)` [go_dn](#local-6989586621679038525) [x2](#local-6989586621679038521)
instance Enum Integer where succ x = x + 1 pred x = x - 1 toEnum (I# n) = smallInteger n fromEnum n = I# (integerToInt n)
{-# INLINE enumFrom #-}
{-# INLINE enumFromThen #-}
{-# INLINE enumFromTo #-}
{-# INLINE enumFromThenTo #-}
[enumFrom](GHC.Enum.html#enumFrom) [x](#local-6989586621679038279) = [enumDeltaInteger](GHC.Enum.html#enumDeltaInteger) [x](#local-6989586621679038279) 1
[enumFromThen](GHC.Enum.html#enumFromThen) [x](#local-6989586621679038280) [y](#local-6989586621679038281) = [enumDeltaInteger](GHC.Enum.html#enumDeltaInteger) [x](#local-6989586621679038280) ([y](#local-6989586621679038281)-[x](#local-6989586621679038280))
[enumFromTo](GHC.Enum.html#enumFromTo) [x](#local-6989586621679038282) [lim](#local-6989586621679038283) = [enumDeltaToInteger](GHC.Enum.html#enumDeltaToInteger) [x](#local-6989586621679038282) 1 [lim](#local-6989586621679038283)
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) [x](#local-6989586621679038284) [y](#local-6989586621679038285) [lim](#local-6989586621679038286) = [enumDeltaToInteger](GHC.Enum.html#enumDeltaToInteger) [x](#local-6989586621679038284) ([y](#local-6989586621679038285)-[x](#local-6989586621679038284)) [lim](#local-6989586621679038286)
{-# RULES
"enumDeltaInteger" [1] forall x y. enumDeltaInteger x y = build (\c _ -> enumDeltaIntegerFB c x y)
"efdtInteger" [1] forall x d l. enumDeltaToInteger x d l = build (\c n -> enumDeltaToIntegerFB c n x d l)
"efdtInteger1" [~1] forall x l. enumDeltaToInteger x 1 l = build (\c n -> enumDeltaToInteger1FB c n x l)
"enumDeltaToInteger1FB" [1] forall c n x. enumDeltaToIntegerFB c n x 1 = enumDeltaToInteger1FB c n x
"enumDeltaInteger" [1] enumDeltaIntegerFB (:) = enumDeltaInteger "enumDeltaToInteger" [1] enumDeltaToIntegerFB (:) [] = enumDeltaToInteger "enumDeltaToInteger1" [1] enumDeltaToInteger1FB (:) [] = enumDeltaToInteger1 #-}
{-# INLINE [0] enumDeltaIntegerFB #-}
enumDeltaIntegerFB :: (Integer -> b -> b) -> Integer -> Integer -> b
enumDeltaIntegerFB c x0 d = go x0
where go x = x seq
(x [c](#local-6989586621679038527)
go (x+d))
{-# NOINLINE [1] enumDeltaInteger #-}
enumDeltaInteger :: Integer -> Integer -> [Integer]
enumDeltaInteger x d = x seq
(x : enumDeltaInteger (x+d) d)
{-# INLINE [0] enumDeltaToIntegerFB #-}
enumDeltaToIntegerFB :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a enumDeltaToIntegerFB c n x delta lim | delta >= 0 = up_fb c n x delta lim | otherwise = dn_fb c n x delta lim
{-# INLINE [0] enumDeltaToInteger1FB #-}
enumDeltaToInteger1FB :: (Integer -> a -> a) -> a
-> Integer -> Integer -> a
enumDeltaToInteger1FB c n x0 lim = go (x0 :: Integer)
where
go x | x > lim = n
| otherwise = x [c](#local-6989586621679038539)
go (x+1)
{-# NOINLINE [1] enumDeltaToInteger #-} enumDeltaToInteger :: Integer -> Integer -> Integer -> [Integer] enumDeltaToInteger x delta lim | delta >= 0 = up_list x delta lim | otherwise = dn_list x delta lim
{-# NOINLINE [1] enumDeltaToInteger1 #-} enumDeltaToInteger1 :: Integer -> Integer -> [Integer]
enumDeltaToInteger1 x0 lim = go (x0 :: Integer) where go x | x > lim = [] | otherwise = x : go (x+1)
up_fb :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a
up_fb c n x0 delta lim = go (x0 :: Integer)
where
go x | x > lim = n
| otherwise = x [c](#local-6989586621679038552)
go (x+delta)
dn_fb :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a
dn_fb c n x0 delta lim = go (x0 :: Integer)
where
go x | x < lim = n
| otherwise = x [c](#local-6989586621679038559)
go (x+delta)
up_list :: Integer -> Integer -> Integer -> [Integer] up_list x0 delta lim = go (x0 :: Integer) where go x | x > lim = [] | otherwise = x : go (x+delta) dn_list :: Integer -> Integer -> Integer -> [Integer] dn_list x0 delta lim = go (x0 :: Integer) where go x | x < lim = [] | otherwise = x : go (x+delta)
#if defined(MIN_VERSION_integer_gmp)
instance Enum Natural where
succ n = n [plusNatural](GHC.Natural.html#plusNatural)
wordToNaturalBase 1##
pred n = n [minusNatural](GHC.Natural.html#minusNatural)
wordToNaturalBase 1##
[toEnum](GHC.Enum.html#toEnum) = [intToNatural](GHC.Natural.html#intToNatural)
[fromEnum](GHC.Enum.html#fromEnum) ([NatS#](GHC.Natural.html#NatS%23) [w](#local-6989586621679038264))
| [i](#local-6989586621679038265) >= 0 = [i](#local-6989586621679038265)
| [otherwise](GHC.Base.html#otherwise) = [errorWithoutStackTrace](GHC.Err.html#errorWithoutStackTrace) "fromEnum: out of Int range"
where
[i](#local-6989586621679038265) = I# (word2Int# [w](#local-6989586621679038264))
fromEnum [n](#local-6989586621679038266) = [fromEnum](GHC.Enum.html#fromEnum) ([naturalToInteger](GHC.Natural.html#naturalToInteger) [n](#local-6989586621679038266))
[enumFrom](GHC.Enum.html#enumFrom) [x](#local-6989586621679038267) = [enumDeltaNatural](GHC.Enum.html#enumDeltaNatural) [x](#local-6989586621679038267) ([wordToNaturalBase](GHC.Natural.html#wordToNaturalBase) 1##)
[enumFromThen](GHC.Enum.html#enumFromThen) [x](#local-6989586621679038268) [y](#local-6989586621679038269)
| [x](#local-6989586621679038268) <= [y](#local-6989586621679038269) = [enumDeltaNatural](GHC.Enum.html#enumDeltaNatural) [x](#local-6989586621679038268) ([y](#local-6989586621679038269)-[x](#local-6989586621679038268))
| [otherwise](GHC.Base.html#otherwise) = [enumNegDeltaToNatural](GHC.Enum.html#enumNegDeltaToNatural) [x](#local-6989586621679038268) ([x](#local-6989586621679038268)-[y](#local-6989586621679038269)) ([wordToNaturalBase](GHC.Natural.html#wordToNaturalBase) 0##)
[enumFromTo](GHC.Enum.html#enumFromTo) [x](#local-6989586621679038270) [lim](#local-6989586621679038271) = [enumDeltaToNatural](GHC.Enum.html#enumDeltaToNatural) [x](#local-6989586621679038270) ([wordToNaturalBase](GHC.Natural.html#wordToNaturalBase) 1##) [lim](#local-6989586621679038271)
[enumFromThenTo](GHC.Enum.html#enumFromThenTo) [x](#local-6989586621679038272) [y](#local-6989586621679038273) [lim](#local-6989586621679038274)
| [x](#local-6989586621679038272) <= [y](#local-6989586621679038273) = [enumDeltaToNatural](GHC.Enum.html#enumDeltaToNatural) [x](#local-6989586621679038272) ([y](#local-6989586621679038273)-[x](#local-6989586621679038272)) [lim](#local-6989586621679038274)
| [otherwise](GHC.Base.html#otherwise) = [enumNegDeltaToNatural](GHC.Enum.html#enumNegDeltaToNatural) [x](#local-6989586621679038272) ([x](#local-6989586621679038272)-[y](#local-6989586621679038273)) [lim](#local-6989586621679038274)
enumDeltaNatural :: Natural -> Natural -> [Natural]
enumDeltaNatural d = x : enumDeltaNatural (x+d) d
enumDeltaToNatural :: Natural -> Natural -> Natural -> [Natural] enumDeltaToNatural x0 delta lim = go x0 where go x | x > lim = [] | otherwise = x : go (x+delta)
enumNegDeltaToNatural :: Natural -> Natural -> Natural -> [Natural] enumNegDeltaToNatural x0 ndelta lim = go x0 where go x | x < lim = [] | x >= ndelta = x : go (x-ndelta) | otherwise = [x]
#else
instance Enum Natural where pred (Natural 0) = errorWithoutStackTrace "Natural.pred: 0" pred (Natural n) = Natural (pred n) {-# INLINE pred #-} succ (Natural n) = Natural (succ n) {-# INLINE succ #-} fromEnum (Natural n) = fromEnum n {-# INLINE fromEnum #-} toEnum n | n < 0 = errorWithoutStackTrace "Natural.toEnum: negative" | otherwise = Natural (toEnum n) {-# INLINE toEnum #-}
enumFrom = coerce (enumFrom :: Integer -> [Integer]) enumFromThen x y | x <= y = coerce (enumFromThen :: Integer -> Integer -> [Integer]) x y | otherwise = enumFromThenTo x y (wordToNaturalBase 0##)
enumFromTo = coerce (enumFromTo :: Integer -> Integer -> [Integer]) enumFromThenTo = coerce (enumFromThenTo :: Integer -> Integer -> Integer -> [Integer])
#endif
deriving instance Bounded VecCount
deriving instance Enum VecCount
deriving instance Bounded VecElem
deriving instance Enum VecElem