fork download
  1. linefun :: (Double, Double) -> (Double, Double) -> Double -> Double
  2. linefun (x1, y1) (x2, y2) =
  3. let dx = x2 - x1
  4. dy = y2 - y1
  5. k = dy / dx
  6. b = y1 - k * x1 in
  7. \x -> k*x + b
  8.  
  9. printf f x = putStrLn $ "f( " ++ show x ++ " ) = " ++ show (f x)
  10.  
  11. main = mapM_ (printf $ linefun (0, 1) (1, 3)) [0..4]
Success #stdin #stdout 0s 5720KB
stdin
Standard input is empty
stdout
f( 0.0 ) = 1.0
f( 1.0 ) = 3.0
f( 2.0 ) = 5.0
f( 3.0 ) = 7.0
f( 4.0 ) = 9.0