I was recently telling lispy about some Haskell I was trying to write. I decided I'd try porting one of my Python scripts to Haskell. The script is used in emacs when composing e-mail replies and needs to do things like format citation text. One function I wrote computes the largest common prefix of a list of strings. He ended up reducing it about threefold from my original Haskell; here was the result:
1 2 3 4 5 6 | commonPrefix :: String -> String -> String
commonPrefix a b = map fst $ takeWhile (uncurry (==)) (zip a b)
commonPrefixLines :: [String] -> String
commonPrefixLines [] = ""
commonPrefixLines lines = foldl1 commonPrefix lines
|
I think that's pretty elegant. Thanks, lispy.