Skip to content

Commit

Permalink
i hate needles
Browse files Browse the repository at this point in the history
  • Loading branch information
barak committed Apr 16, 2009
1 parent 59836ab commit c6b11dd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions List/Util.hs
Expand Up @@ -8,8 +8,8 @@ where


zipWithDefaults :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c] zipWithDefaults :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c]
zipWithDefaults f x0 y0 [] [] = [] zipWithDefaults f x0 y0 [] [] = []
zipWithDefaults f x0 y0 xs [] = map (flip f y0) xs zipWithDefaults f x0 y0 xs [] = map (`f`y0) xs
zipWithDefaults f x0 y0 [] ys = map (f x0) ys 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 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 -- | The 'indexDefault' function indexes into a list like @(!!)@, but
Expand All @@ -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 :: Maybe a -> [a] -> Int -> a


indexDefault _ _ i | i<0 = error "negative index" indexDefault _ _ i | i<0 = error "negative index"
indexDefault _ (x:_) 0 = x indexDefault _ (x:_) 0 = x
indexDefault Nothing [x] _ = x indexDefault Nothing [x] _ = x
indexDefault (Just def) [] _ = def indexDefault (Just x) [] _ = x
indexDefault m (x:xs) i = indexDefault m xs (i-1) indexDefault m (_:xs) i = indexDefault m xs (i-1)
indexDefault Nothing [] 0 = error "no ultimate element" indexDefault Nothing [] 0 = error "no ultimate element"

0 comments on commit c6b11dd

Please sign in to comment.