1 {- tpk.hs: Knuth's TPK program in the Haskell programming language -} 2 module Main where 3 4 import System.IO as IO -- import monadic I/O functions 5 import Text.Printf -- import text formating function 6 7 main = 8 do IO.getContents >>= IO.putStr . unlines . h . lines 9 10 f :: Float -> Float 11 f x = sqrt (abs x) + 5.0*(x**3.0) 12 13 g :: (Int, Float) -> String 14 g (n,x) = 15 if y>400.0 16 then printf "%d TOO LARGE" (n::Int) 17 else printf "%d %f" (n::Int) (y::Float) 18 where y = f(x) 19 20 h :: [String] -> [String] 21 h = map g . reverse . zip [1..10] . map read