Using existential types

Tim Docker timd at macquarie.com.au
Mon Oct 13 21:17:08 EDT 2003


oleg wrote:

> Sorry I didn't know of that requirement. The desired sharing 
> can easily be introduced:

That's always a risk with posting a toy example - which bits
are important can be hard to tell. You are right of course
about being able to introduce the sharing.

FWIW, after the suggestions that I've had (thanks!), my
"existential-free" example is as below.

Tim



type ColumnFn rowv = [rowv] -> ([String],String)

column :: (rowv->a) -> ([a]->a) -> (a->String) -> ColumnFn
column valf sumf fmtf rows = (map fmtf vals, (fmtf.sumf) vals)
    where vals = map valf rows

calculate :: [ColumnFn rowv] -> [rowv] -> ([String],String)
calculate cfs rows = [ cf rows | cf <- cfs ]


----

rows = ["I","wish","to","define","a","report"]

cols = [
    column id                          (\_ -> "") id,
    column length                      sum        show,
    column (\s -> length s * length s) maximum    show
    ]
:r
values = [ calculate rows col | col <- cols ] 


More information about the Haskell-Cafe mailing list