1 module PreludeBuiltin where
3 --- 2-tuples ------------------------------------------
12 import List ( (++), foldr )
13 import Prel ( (&&), (||), (.) )
14 import PS ( _PackedString, _unpackPS )
19 instance (Eq a, Eq b) => Eq (a, b) where
20 (a,b) == (c,d) = a == c && b == d
21 (a,b) /= (c,d) = a /= c || b /= d
23 instance (Ord a, Ord b) => Ord (a, b) where
24 a < b = case _tagCmp a b of { _LT -> True; _EQ -> False; _GT -> False }
25 a <= b = case _tagCmp a b of { _LT -> True; _EQ -> True; _GT -> False }
26 a >= b = case _tagCmp a b of { _LT -> False; _EQ -> True; _GT -> True }
27 a > b = case _tagCmp a b of { _LT -> False; _EQ -> False; _GT -> True }
28 max a b = case _tagCmp a b of { _LT -> b; _EQ -> a; _GT -> a }
29 min a b = case _tagCmp a b of { _LT -> a; _EQ -> a; _GT -> b }
30 _tagCmp (a1, b1) (a2, b2) = case (_tagCmp a1 a2) of
35 instance (Ix a, Ix b) => Ix (a, b) where
36 range ((l1,l2),(u1,u2))
37 = [ (i1,i2) | i1 <- range (l1,u1), i2 <- range (l2,u2) ]
39 index ((l1,l2),(u1,u2)) (i1,i2)
40 = index (l1,u1) i1 * (index (l2,u2) u2 + 1){-rangeSize (l2,u2)-} + index (l2,u2) i2
42 inRange ((l1,l2),(u1,u2)) (i1,i2)
43 = inRange (l1,u1) i1 && inRange (l2,u2) i2
45 instance (Text a, Text b) => Text (a, b) where
46 readsPrec p = readParen False
47 (\r -> [((x,y), w) | ("(",s) <- lex r,
48 (x,t) <- readsPrec 0 s,
50 (y,v) <- readsPrec 0 u,
53 showsPrec p (x,y) = showChar '(' . showsPrec 0 x . showString ", " .
54 showsPrec 0 y . showChar ')'
56 readList = _readList (readsPrec 0)
57 showList = _showList (showsPrec 0)
59 {-# SPECIALIZE instance Eq (Int, Int) #-}
60 {-# SPECIALIZE instance Ord (Int, Int) #-}
61 {-# SPECIALIZE instance Ix (Int, Int) #-}
62 {-# SPECIALIZE instance Text (Int, Int) #-}
64 {-# SPECIALIZE instance Text (Integer, Integer) #-}
65 {-# SPECIALIZE instance Text ((Int,Int),(Int,Int)) #-}
67 {-# SPECIALIZE instance Eq ([Char], [Char]) #-}
68 {-# SPECIALIZE instance Ord ([Char], [Char]) #-}
70 {-# SPECIALIZE instance Eq ([Int], [Int]) #-}
71 {-# SPECIALIZE instance Ord ([Int], [Int]) #-}
73 {-# SPECIALIZE instance Eq (_PackedString, _PackedString) #-}
74 {-# SPECIALIZE instance Ord (_PackedString, _PackedString) #-}
76 #if defined(__UNBOXED_INSTANCES__)
77 -- We generate SPECIALIZED instances for all combinations of unboxed pairs
79 {-# GENERATE_SPECS instance a b :: Eq (a,b) #-}
80 {-# GENERATE_SPECS instance a b :: Ord (a,b) #-}
81 {-# GENERATE_SPECS instance a{Char#,Int#} b{Char#,Int#} :: Ix (a,b) #-}
82 {-# GENERATE_SPECS instance a b :: Text (a,b) #-}
84 {-# SPECIALIZE instance Eq ([Char#], [Char#]) #-}
85 {-# SPECIALIZE instance Ord ([Char#], [Char#]) #-}
87 {-# SPECIALIZE instance Eq ([Int#], [Int#]) #-}
88 {-# SPECIALIZE instance Ord ([Int#], [Int#]) #-}
90 #endif {-UNBOXED INSTANCES-}