Using existential types

Tim Docker timd at macquarie.com.au
Fri Oct 10 19:19:05 EDT 2003


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


More information about the Haskell-Cafe mailing list