[Haskell-cafe] Set of reals...?
Glynn Clements
glynn at gclements.plus.com
Thu Oct 28 23:21:22 EDT 2004
Stijn De Saeger wrote:
> Now, for unions I tried the following:
> to take the union of two BasicSets, just append them and contract the result.
> contracting meaning: merge overlapping intervals.
>
> > contract :: Range -> Range -> BasicSet
> > contract (x1,y1) (x2,y2)
> > | x2 <= y1 = if x2 >= x1 then [(x1, (max y1 y2))] else
> > if y2 >= x1 then [(x2, (max y1 y2))] else [(x2,y2), (x1,y1)]
> > | x1 <= y2 = if x1 >= x2 then [(x2, (max y1 y2))] else
> > if y1 >= x2 then [(x1, (max y1 y2))] else [(x1,y1), (x2,y2)]
> > | x1 <= x2 = [(x1,y1), (x2, y2)]
>
>
> Now generalizing this from Ranges to BasicSets is where i got stuck.
> In my limited grasp of haskell and FP, this contractSet function below
> is just crying for the use of a fold operation, but i can't for the
> life of me see how to do it.
As the result is a BasicSet, the accumulator would need to be a
BasicSet and the operator would need to have type:
BasicSet -> Range -> BasicSet
This can presumably be implemented as a fold on contract, so
contractSet would essentially be a doubly-nested fold.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the Haskell-Cafe
mailing list