| classify :: Eq b => [a->b] -> [a] -> [[[a]]] | classify cs xs = ... | | where for each classifying function in cs, I would get the xs | partitioned accordingly. E.g. | | classify [fst,snd] [(1,0), (1,2), (2,0)] | | would yield | | [ [(1,0), (1,2)], [(2,0)] -- classified by `fst` | , [(1,0), (2,0)], [(1,2)]] -- classified by `snd` | | Now, obviously, the problem is that fst and snd, being passed in a | list, needs to be of the same type; this complicates classifying a | list of type [(Int,Bool)], for instance¹.
Use existentials data Classifier a = forall b. Ord b => CL (a->b) classify :: [Classifier a] -> [a] -> [[[a]]] classify cls as = map (classify1 as) cls classify1 :: Classifier a -> [a] -> [[a]] classify1 (CL f) as = ... classify as using f.... Think of a classifier (CL f) as a pair of a) a function f:a->b b) an Ord dictionary for comparing b's I forget whether I've aired this on the list, but I'm seriously thinking that we should change 'forall' to 'exists' in existential data constructors like this one. One has to explain 'forall' every time. But we'd lose a keyword. Simon _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell