Matt McCutchen's Web Site
/
match
/
match.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
2218dfe
)
Formatter: Rewrite code that used an n + k pattern
author
Matt McCutchen
<matt@mattmccutchen.net>
Sat, 27 Aug 2011 15:06:22 +0000
(11:06 -0400)
committer
Matt McCutchen
<matt@mattmccutchen.net>
Sat, 27 Aug 2011 15:06:22 +0000
(11:06 -0400)
program/Formatter.hs
patch
|
blob
|
blame
|
history
diff --git
a/program/Formatter.hs
b/program/Formatter.hs
index
ed851b3
..
aab845c
100644
(file)
--- a/
program/Formatter.hs
+++ b/
program/Formatter.hs
@@
-8,7
+8,11
@@
intercalate xs xss = concat (intersperse xs xss)
padWith :: a -> Int -> [a] -> [a]
padWith _ 0 l = l
padWith e n [] = replicate n e
-padWith e (n+1) (h:t) = h:(padWith e n t)
+-- http://hackage.haskell.org/trac/haskell-prime/wiki/RemoveNPlusK
+-- Ugg... GHC could at least give a meaningful error message. ~ Matt 2011-08-27
+padWith e n (h:t) =
+ if n == 0 then error "padWith: list is already longer than the requested length"
+ else h:(padWith e (n-1) t)
formatTable :: [[String]] -> String
formatTable cells =