[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / lib / prelude / IList.hs
1 module PreludeBuiltin where
2
3 import Prel             ( (&&) )
4 import Cls
5 import Core             ( _readList, _showList )
6 import IChar
7 import IInt
8 import List             ( (++) )
9 import PS               ( _PackedString, _unpackPS )
10 import Text
11
12 instance (Eq a) => Eq [a]  where
13     []     == []     = True     
14     (x:xs) == (y:ys) = x == y && xs == ys
15     []     == ys     = False                    
16     xs     == []     = False                    
17     xs     /= ys     = if (xs == ys) then False else True
18
19 instance (Ord a) => Ord [a] where
20     a <  b  = case _tagCmp a b of { _LT -> True;  _EQ -> False; _GT -> False }
21     a <= b  = case _tagCmp a b of { _LT -> True;  _EQ -> True;  _GT -> False }
22     a >= b  = case _tagCmp a b of { _LT -> False; _EQ -> True;  _GT -> True  }
23     a >  b  = case _tagCmp a b of { _LT -> False; _EQ -> False; _GT -> True  }
24
25     max a b = case _tagCmp a b of { _LT -> b; _EQ -> a;  _GT -> a }
26     min a b = case _tagCmp a b of { _LT -> a; _EQ -> a;  _GT -> b }
27
28     _tagCmp []     []     = _EQ
29     _tagCmp (x:xs) []     = _GT
30     _tagCmp []     (y:ys) = _LT
31     _tagCmp (x:xs) (y:ys) = case _tagCmp x y of
32                                  _LT -> _LT     
33                                  _GT -> _GT             
34                                  _EQ -> _tagCmp xs ys
35
36 instance  (Text a) => Text [a]  where
37     readsPrec p = readList
38     showsPrec p = showList
39
40 {-# SPECIALIZE instance Eq   [Char] #-}
41 {-# SPECIALIZE instance Ord  [Char] #-}
42 {-# SPECIALIZE instance Text [Char] #-}
43
44 #if defined(__OVERLAPPING_INSTANCES__)
45 instance _CCallable   [Char]
46 instance _CReturnable [Char]
47 #endif
48
49 {-# SPECIALIZE instance Eq   [Int]  #-}
50 {-# SPECIALIZE instance Ord  [Int] #-}
51 {-# SPECIALIZE instance Text [Int] #-}
52
53
54 #if defined(__UNBOXED_INSTANCES__)
55
56 {-# GENERATE_SPECS instance a :: Eq   [a] #-}
57 {-# GENERATE_SPECS instance a :: Ord  [a] #-}
58 {-# GENERATE_SPECS instance a :: Text [a] #-}
59
60 instance _CCallable   [Char#]
61 instance _CReturnable [Char#]
62
63 #endif