fork download
  1. import Data.List
  2. import Data.Function
  3.  
  4. newtype Point a = Point {getPoint :: (a,a)}
  5. data Table a = Table {getHdr :: String, getTable :: [Point a]}
  6.  
  7. instance Show a => Show (Point a) where
  8. show p = (((++) . (++ "\t")) `on` (\f -> (show . f . getPoint $ p))) fst snd
  9.  
  10. instance Show a => Show (Table a) where
  11. show t = intercalate "\n" $ show (let [x,y] = getHdr t in point (const y) x) : fmap show (getTable t)
  12.  
  13. point f x = Point (x, f x)
  14. table h f xs = Table h $ fmap (point f) xs
  15.  
  16. tableYT = table "ty" ((\a b t -> exp(abs(a + cos (b * t)))) 0.5 2) [2, 2.5 .. 5]
  17. tableYX = table "xy" ((\a x -> 0.5*x*(1 + a*x)**0.2) 3.5) [1 .. 10]
  18.  
  19. main = mapM_ print [tableYT, tableYX]
Success #stdin #stdout 0s 8388607KB
stdin
Standard input is empty
stdout
't'	'y'
2.0	1.1660752478305285
2.5	2.189475867910451
3.0	4.306692838204567
3.5	3.503989772782061
4.0	1.4254676940041255
4.5	1.508521846659017
5.0	1.4036437429626065
'x'	'y'
1.0	0.6754800192603068
2.0	1.5157165665103982
3.0	2.4447295790194934
4.0	3.4375438551749578
5.0	4.480993916988398
6.0	5.566802208774253
7.0	6.689229254634084
8.0	7.844036229818192
9.0	9.027950848886173
10.0	10.238362555396098