On 30 Apr 2015 23:08, "Matt Oliveri" <[email protected]> wrote:
>
> On Thu, Apr 30, 2015 at 5:39 PM, Raoul Duke <[email protected]> wrote:
> >>> and the fast-union would require all sets
> >>> to have the same type.
> >>
> >> No it wouldn't. It needs the two sets it was passed to have the same
> >> element type and ordering, and it needs to have access to the
> >> comparator for that ordering.
> >
> > It makes sense to me that we are better off splitting out as many
> > types/interfaces as possible.
> >
> > e.g. Set+{Ascending,Descending,Random >> SetAscending, SetDescending,
SetRandom.
>
> Then how do you define fast union generically? No, I think the order
> really wants to be a parameter of the Set family.

I want the order to be a _type_ parameter of the set type.

You define fast union genetically by only defining instances where the
order is the same, and using phantom types, so:

data Set order element = S order [element]

data Ord o = O o {
    cmp :: x -> y -> Bool
}

data AscendingNumeric = AN

oan = O AN {
   cmp = <
}

union :: Set o e -> Set o e -> Set o e
union (S cmp l1) (S _ l2) ...

set1 = S oan [1, 3, 5]
set2 = S oan [2, 4, 6]
set3 = union set1 set2

Keean.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to