
10 Oct
2003
10 Oct
'03
8:19 a.m.
Thanks for the comments. I think your solution misses one point in my original example... I wrote:
data ColDesc rowv = forall a. ColDesc (rowv -> a) ([a] -> a) (a -> String)
calculate :: [rowv] -> ColDesc rowv -> ([String],String) calculate rs (ColDesc valf sumf fmtf) = let vals = map valf rs in (map fmtf vals, (fmtf.sumf) vals)
This code only does the (rowv -> a) evaluation once, whereas olegs version:
calculate :: [rowv] -> ColDesc rowv -> ([String],String) calculate rs (ColDesc fmtf sumf) = (map fmtf rs, sumf rs)
does the evaluation (rowv -> a) for each element twice, I think. In a real system, as opposed to my toy example, this computation is expensive, and I don't want to do it more that necessary. Tim