[project @ 1996-01-18 16:33:17 by partain]
[ghc-hetmet.git] / ghc / lib / prelude / ITup5.hs
1 module PreludeBuiltin where
2
3 --- 5-tuples ------------------------------------------
4
5 import Cls
6 import Core
7 import IChar
8 import IInt
9 import IList
10 import List             ( (++), foldr )
11 import Prel             ( (&&), (.) )
12 import PS               ( _PackedString, _unpackPS )
13 import Text
14 import TyArray
15 import TyComplex
16
17 instance (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a,b,c,d,e) where
18     (a1,a2,a3,a4,a5) == (b1,b2,b3,b4,b5) = a1 == b1 && a2 == b2 && a3 == b3 && a4 == b4 && a5 == b5
19     aaaaa            /= bbbbb            = if (aaaaa == bbbbb) then False else True
20
21 instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a,b,c,d,e) where
22     a <  b  = case _tagCmp a b of { _LT -> True;  _EQ -> False; _GT -> False }
23     a <= b  = case _tagCmp a b of { _LT -> True;  _EQ -> True;  _GT -> False }
24     a >= b  = case _tagCmp a b of { _LT -> False; _EQ -> True;  _GT -> True  }
25     a >  b  = case _tagCmp a b of { _LT -> False; _EQ -> False; _GT -> True  }
26
27     max a b = case _tagCmp a b of { _LT -> b; _EQ -> a;  _GT -> a }
28     min a b = case _tagCmp a b of { _LT -> a; _EQ -> a;  _GT -> b }
29
30     _tagCmp (a1, b1, c1, d1, e1) (a2, b2, c2, d2, e2)
31       = case (_tagCmp a1 a2) of {
32           _LT -> _LT;
33           _GT -> _GT;
34           _EQ -> case _tagCmp b1 b2 of {
35                       _LT -> _LT;
36                       _GT -> _GT;
37                       _EQ -> case _tagCmp c1 c2 of {
38                                   _LT -> _LT;
39                                   _GT -> _GT;
40                                   _EQ -> case _tagCmp d1 d2 of {
41                                               _LT -> _LT;
42                                               _GT -> _GT;
43                                               _EQ -> _tagCmp e1 e2
44                                             }
45                                 }
46                     }
47         }
48
49 instance  (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1,a2,a3,a4,a5)  where
50     range ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) =
51         [(i1,i2,i3,i4,i5) | i1 <- range (l1,u1),
52                             i2 <- range (l2,u2),
53                             i3 <- range (l3,u3),
54                             i4 <- range (l4,u4),
55                             i5 <- range (l5,u5)]
56
57     index ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) (i1,i2,i3,i4,i5) =
58       index (l5,u5) i5 + rangeSize (l5,u5) * (
59         index (l4,u4) i4 + rangeSize (l4,u4) * (
60          index (l3,u3) i3 + rangeSize (l3,u3) * (
61            index (l2,u2) i2 + rangeSize (l2,u2) * (
62              index (l1,u1) i1))))
63       where
64         rangeSize (l,u) = index (l,u) u + (1 :: Int)
65
66     inRange ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) (i1,i2,i3,i4,i5) =
67         inRange (l1,u1) i1 && inRange (l2,u2) i2 &&
68             inRange (l3,u3) i3 && inRange (l4,u4) i4 && inRange (l5,u5) i5
69
70 -- ToDo: something for Binary
71
72 instance (Text a, Text b, Text c, Text d, Text e) => Text (a, b, c, d, e) where
73     readsPrec p = readParen False
74                     (\a -> [((w,x,y,z,v), l) | ("(",b) <- lex a,
75                                                (w,c)   <- readsPrec 0 b,
76                                                (",",d) <- lex c,
77                                                (x,e)   <- readsPrec 0 d,
78                                                (",",f) <- lex e,
79                                                (y,g)   <- readsPrec 0 f,
80                                                (",",h) <- lex g,
81                                                (z,i)   <- readsPrec 0 h,
82                                                (",",j) <- lex i,
83                                                (v,k)   <- readsPrec 0 j,
84                                                (")",l) <- lex k ] )
85
86     showsPrec p (v,w,x,y,z) = showChar '(' . showsPrec 0 v . showString ", " .
87                                              showsPrec 0 w . showString ", " .
88                                              showsPrec 0 x . showString ", " .
89                                              showsPrec 0 y . showString ", " .
90                                              showsPrec 0 z . showChar ')'
91
92     readList    = _readList (readsPrec 0)
93     showList    = _showList (showsPrec 0) 
94
95
96 {-# SPECIALIZE instance Eq   (Int,Int,Int,Int,Int) #-}
97 {-# SPECIALIZE instance Ord  (Int,Int,Int,Int,Int) #-}