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
- metaperl's blog
- Login to post comments
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?
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 :-)
The Longest.hs solution seems a tad overkill to me.