+% -----------------------------------------------------------------------------
+% $Id: PrelEnum.lhs,v 1.14 2001/07/24 06:31:35 ken Exp $
%
-% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
+% (c) The University of Glasgow, 1992-2000
%
+
\section[PrelBounded]{Module @PrelBounded@}
Instances of Bounded for various datatypes.
module PrelEnum(
Bounded(..), Enum(..),
- enumFromBounded, enumFromThenBounded,
+ boundedEnumFrom, boundedEnumFromThen,
-- Instances for Bounded and Eum: (), Char, Int
enumFromThenTo x1 x2 y = map toEnum [fromEnum x1, fromEnum x2 .. fromEnum y]
-- Default methods for bounded enumerations
-enumFromBounded :: (Enum a, Bounded a) => a -> [a]
-enumFromBounded n = map toEnum [fromEnum n .. fromEnum (maxBound `asTypeOf` n)]
+boundedEnumFrom :: (Enum a, Bounded a) => a -> [a]
+boundedEnumFrom n = map toEnum [fromEnum n .. fromEnum (maxBound `asTypeOf` n)]
-enumFromThenBounded :: (Enum a, Bounded a) => a -> a -> [a]
-enumFromThenBounded n1 n2
+boundedEnumFromThen :: (Enum a, Bounded a) => a -> a -> [a]
+boundedEnumFromThen n1 n2
| i_n2 >= i_n1 = map toEnum [i_n1, i_n2 .. fromEnum (maxBound `asTypeOf` n1)]
| otherwise = map toEnum [i_n1, i_n2 .. fromEnum (minBound `asTypeOf` n1)]
where
fromEnum True = oneInt
-- Use defaults for the rest
- enumFrom = enumFromBounded
- enumFromThen = enumFromThenBounded
+ enumFrom = boundedEnumFrom
+ enumFromThen = boundedEnumFromThen
\end{code}
%*********************************************************
fromEnum GT = twoInt
-- Use defaults for the rest
- enumFrom = enumFromBounded
- enumFromThen = enumFromThenBounded
+ enumFrom = boundedEnumFrom
+ enumFromThen = boundedEnumFromThen
\end{code}
%*********************************************************
\begin{code}
instance Bounded Char where
minBound = '\0'
- maxBound = '\255'
+ maxBound = '\x10FFFF'
instance Enum Char where
succ (C# c#)
- | not (ord# c# ==# 255#) = C# (chr# (ord# c# +# 1#))
+ | not (ord# c# ==# 0x10FFFF#) = C# (chr# (ord# c# +# 1#))
| otherwise = error ("Prelude.Enum.Char.succ: bad argument")
pred (C# c#)
| not (ord# c# ==# 0#) = C# (chr# (ord# c# -# 1#))
fromEnum = ord
{-# INLINE enumFrom #-}
- enumFrom (C# x) = eftChar (ord# x) 255#
+ enumFrom (C# x) = eftChar (ord# x) 0x10FFFF#
-- Blarg: technically I guess enumFrom isn't strict!
{-# INLINE enumFromTo #-}
-- For enumFromThenTo we give up on inlining
efdCharFB c n x1 x2
- | delta >=# 0# = go_up_char_fb c n x1 delta 255#
+ | delta >=# 0# = go_up_char_fb c n x1 delta 0x10FFFF#
| otherwise = go_dn_char_fb c n x1 delta 0#
where
delta = x2 -# x1
efdCharList x1 x2
- | delta >=# 0# = go_up_char_list x1 delta 255#
+ | delta >=# 0# = go_up_char_list x1 delta 0x10FFFF#
| otherwise = go_dn_char_list x1 delta 0#
where
delta = x2 -# x1
fromEnum x = x
{-# INLINE enumFrom #-}
- enumFrom (I# x) = eftInt x 2147483647#
+ enumFrom (I# x) = case maxInt of I# y -> eftInt x y
-- Blarg: technically I guess enumFrom isn't strict!
{-# INLINE enumFromTo #-}
lim = y -# delta
efdIntFB c n x1 x2
- | delta >=# 0# = go_up_int_fb c n x1 delta ( 2147483647# -# delta)
- | otherwise = go_dn_int_fb c n x1 delta ((-2147483648#) -# delta)
+ | delta >=# 0# = case maxInt of I# y -> go_up_int_fb c n x1 delta (y -# delta)
+ | otherwise = case minInt of I# y -> go_dn_int_fb c n x1 delta (y -# delta)
where
delta = x2 -# x1
efdIntList x1 x2
- | delta >=# 0# = go_up_int_list x1 delta ( 2147483647# -# delta)
- | otherwise = go_dn_int_list x1 delta ((-2147483648#) -# delta)
+ | delta >=# 0# = case maxInt of I# y -> go_up_int_list x1 delta (y -# delta)
+ | otherwise = case minInt of I# y -> go_dn_int_list x1 delta (y -# delta)
where
delta = x2 -# x1