[project @ 2001-03-23 16:36:20 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelEnum.lhs
index 64b599c..0104e46 100644 (file)
@@ -1,16 +1,19 @@
+% -----------------------------------------------------------------------------
+% $Id: PrelEnum.lhs,v 1.13 2001/02/18 14:45:15 qrczak 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.
 
 \begin{code}
-{-# OPTIONS -fcompiling-prelude -fno-implicit-prelude #-}
+{-# OPTIONS -fno-implicit-prelude #-}
 
 module PrelEnum(
        Bounded(..), Enum(..),
-       enumFromBounded, enumFromThenBounded,
+       boundedEnumFrom, boundedEnumFromThen,
 
        -- Instances for Bounded and Eum: (), Char, Int
 
@@ -51,11 +54,11 @@ class  Enum a       where
     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
@@ -130,8 +133,8 @@ instance Enum Bool where
   fromEnum True  = oneInt
 
   -- Use defaults for the rest
-  enumFrom     = enumFromBounded
-  enumFromThen = enumFromThenBounded
+  enumFrom     = boundedEnumFrom
+  enumFromThen = boundedEnumFromThen
 \end{code}
 
 %*********************************************************
@@ -164,8 +167,8 @@ instance Enum Ordering where
   fromEnum GT = twoInt
 
   -- Use defaults for the rest
-  enumFrom     = enumFromBounded
-  enumFromThen = enumFromThenBounded
+  enumFrom     = boundedEnumFrom
+  enumFromThen = boundedEnumFromThen
 \end{code}
 
 %*********************************************************
@@ -177,11 +180,11 @@ instance Enum Ordering where
 \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#))
@@ -191,7 +194,7 @@ instance  Enum Char  where
     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 #-}
@@ -232,13 +235,13 @@ eftCharList x y | x ># y    = []
 
 -- 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