Haskell is a strong metalanguage.

Submitted by metaperl on Fri, 05/27/2005 - 8:40am.

Haskell is very good at describing the structure or pattern involved in something. It excels at compiler design for this very reason.

It is also the reason that 5-line Perl programs take much longer in Haskell. For instance, look at this program to find the file with the longest length in Haskell:

http://www.aetion.com/src/Longest.hs

Submitted by jgoerzen on Sat, 05/28/2005 - 9:39am.

Not a very optimal solution, and I suspect it does more error-checking and formatting than the 5-line Perl program. What's your solution in Perl?

Submitted by jgoerzen on Sat, 05/28/2005 - 9:49am.

Try this version:

import System.Environment

getLength fn = do c <- readFile fn
                  return $ (length $ lines c, fn)

main = do lengths <- (getArgs >>= mapM getLength)
          putStrLn $ "Max is: " ++ show (maximum lengths)

5 lines :-)

Submitted by itkovian on Tue, 05/31/2005 - 7:32am.

The Longest.hs solution seems a tad overkill to me.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.