#!/usr/bin/runhugs import IO import System delta x y | x == y = 1 | otherwise = 0 histo :: [Int] -> Int -> Int histo [] = \y -> 0 histo (x:xs) = \z -> (delta x z) + ((histo xs) z) plusses :: Int -> String plusses 0 = [] plusses (x + 1) = "+" ++ plusses x pluseq :: [Int] -> [String] pluseq x = map (\ y -> (show y) ++ " | " ++ ((plusses.(histo x)) y)) [0..100] hist :: [Int] -> IO[()] hist x = sequence (map putStrLn (pluseq x)) doHist filename = bracket (openFile filename ReadMode) hClose (\h -> do contents <- hGetContents h hist (map (\z -> (read z::Int)) (lines contents))) main :: IO () main = do args<-getArgs doHist (head args) return ()