Skip to main content
2 of 2
incorporate Anders Kaseorg's suggestion
Kevin Reid
  • 1.7k
  • 10
  • 14

Haskell, 133

import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
f[]=[getContents]
f n=map readFile n
l x=[x..]!!sum[32|x>'@',x<'[']

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

Explaining l, the function to lowercase one character:

  • sum[32|condition] is a shorter form of if condition then 32 else 0.
  • [x..]!!count is iterate succ x !! count is toEnum $ fromEnum x + count and shorter than importing and using Data.Char.toLower with a condition to restrict it to ASCII.
  • '@' and '[' are the characters immediately preceding A and following Z, so that I can use < instead of <=.

Thanks to Anders Kaseorg for contributing the sum[...|...] and [x..]!! tricks.

Kevin Reid
  • 1.7k
  • 10
  • 14