From c6b11dd70710063edef3ae6e69a7a0c4a3c5f413 Mon Sep 17 00:00:00 2001 From: "Barak A. Pearlmutter" Date: Thu, 16 Apr 2009 14:16:16 +0100 Subject: [PATCH] i hate needles --- List/Util.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/List/Util.hs b/List/Util.hs index 56cf5c3..07aba9d 100644 --- a/List/Util.hs +++ b/List/Util.hs @@ -8,8 +8,8 @@ where zipWithDefaults :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c] zipWithDefaults f x0 y0 [] [] = [] -zipWithDefaults f x0 y0 xs [] = map (flip f y0) xs -zipWithDefaults f x0 y0 [] ys = map (f x0) ys +zipWithDefaults f x0 y0 xs [] = map (`f`y0) xs +zipWithDefaults f x0 y0 [] ys = map (x0`f`) ys zipWithDefaults f x0 y0 (x:xs) (y:ys) = f x y:zipWithDefaults f x0 y0 xs ys -- | The 'indexDefault' function indexes into a list like @(!!)@, but @@ -18,9 +18,9 @@ zipWithDefaults f x0 y0 (x:xs) (y:ys) = f x y:zipWithDefaults f x0 y0 xs ys indexDefault :: Maybe a -> [a] -> Int -> a -indexDefault _ _ i | i<0 = error "negative index" -indexDefault _ (x:_) 0 = x -indexDefault Nothing [x] _ = x -indexDefault (Just def) [] _ = def -indexDefault m (x:xs) i = indexDefault m xs (i-1) -indexDefault Nothing [] 0 = error "no ultimate element" +indexDefault _ _ i | i<0 = error "negative index" +indexDefault _ (x:_) 0 = x +indexDefault Nothing [x] _ = x +indexDefault (Just x) [] _ = x +indexDefault m (_:xs) i = indexDefault m xs (i-1) +indexDefault Nothing [] 0 = error "no ultimate element"