[add better HasSize instances for list
John Meacham <john@repetae.net>**20050907005637] hunk ./HasSize.hs 1
-
hunk ./HasSize.hs 3
+-- this point of this module is not only to share the 'size' syntax, but to
+-- provide optimally lazy versions of size comparasin functions when dealing
+-- with lazy structures. This is especially useful when having to compare the
+-- size of possibly long lists.
+
+-- it is up to each instance to decide what 'size' means
+
hunk ./HasSize.hs 15
+
hunk ./HasSize.hs 34
-    sizeEQ 0 [] = True
-    sizeEQ _ [] = False
-    sizeEQ 0 _ = False
-    sizeEQ n (_:xs) = sizeEQ (n - 1) xs
+    sizeEQ n _ | n < 0 = False
+    sizeEQ n xs = f n xs where
+        f 0 [] = True
+        f _ [] = False
+        f 0 _ = False
+        f n (_:xs) = sizeEQ (n - 1) xs
+    sizeGT n _ | n < 0 = True
+    sizeGT n xs = f n xs where
+        f 0 (_:_) = True
+        f n [] = False
+        f n (_:xs) = f (n - 1) xs
+    sizeLT n _ | n <= 0 = False
+    sizeLT n xs = f n xs where
+        f 0 _ = False
+        f _ [] = True
+        f n (_:xs) = f (n - 1) xs
hunk ./HasSize.hs 78
+instance (HasSize a,HasSize b,HasSize c) => HasSize (a,b,c) where
+    size (x,y,z) = size x + size y  + size z