[m-rev.] for review: Relax constraint on `diet' elements.
Julien Fischer
jfischer at opturion.com
Fri Feb 27 10:48:38 AEDT 2015
On Wed, 18 Feb 2015, Peter Wang wrote:
> Relax constraint on `diet' elements.
>
> The diet data structure works over any discrete linear order.
> Previously our implementation constrained set elements to instances of
> the `enum' typeclass, which is unnecessarily restrictive as it requires
> that elements can be converted to and from ints without loss of information.
> Lift the restriction by changing the constraint on elements to instances
> of a typeclass with only the requisite operations: less_than, successor,
> predecessor.
>
> library/diet.m:
> Add the new typeclass `diet_element' and provide an instance for
> `int'.
>
> Store elements in the data structure instead of their mappings
> to `int'.
>
> Constrain diet elements to the new typeclass and use its
> methods instead of `int' operations.
>
> The result of the `count' function has type `int' so it is
> necessary to map the number of elements in an interval to an
> `int' at some stage; `enum' captures that fairly well so we
> don't bother with another typeclass. The user can easily produce
> an equivalent function if necessary.
That looks fine.
Cheers,
Julien.
More information about the reviews
mailing list