import Data.Ratio f1, f2 :: (Num a) => a -> a f1 x = x^3 + x - 5 f2 x = x^4 + 2*x - 5 euler :: (Rational -> Rational) -> Rational -> Rational -> [Rational] euler f a b = xs where xs = a : b : map step (zip (tail xs) xs) step (x,x0) = x - (f x)*(x - x0) / (f x - f x0) main = do putStrLn "1. f1(x) = x^3 + x - 5 [1,2]" mapM_ printResult . take 5 $ euler f1 1 2 putStrLn "\n2. f2(x) = x^4 + 2*x - 5 [-2,-1]" mapM_ printResult . take 5 $ euler f2 (-2) (-1) putStrLn "\n3. f2(x) = x^4 + 2*x - 5 [1,2]" mapM_ printResult . take 5 $ euler f2 1 2 printResult :: Rational -> IO () printResult x = do putStr . show $ x putStr " ---> " putStrLn . show $ (fromRational x :: Double)