in reply to Golf: Length of longest line in a file

Meh, everyone's beat mine.

#!/usr/bin/runhaskell import IO main=do t<-(hGetContents stdin);putStrLn$show$foldl max 0$map length$l +ines t

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Golf: Length of longest line in a file
by mellon85 (Monk) on Jul 04, 2010 at 08:15 UTC
    well, you could have used liftM and merge map length in the fold function

    liftM (foldl (\x y -> max x $ length y) 0 . lines) $hGetContents stdin

    oh.. wait.. what is this?
Re^2: Golf: Length of longest line in a file
by ambrus (Abbot) on Jul 04, 2010 at 10:44 UTC

    Wouldn't getContents from the prelude work instead of IO.getContents? This shortens a lot because now you can use ghc -e instead of runhaskell, eg.

    #!/bin/sh ghc -e 'getContents>>=print.maximum.map length.lines'

    We also use some other functions of the Prelude for brevity. Note that the code can't be in the same argument as -e.