[m-dev.] for review: use bitsets in quantification
Ralph Becket
rbeck at microsoft.com
Fri Nov 3 21:22:54 AEDT 2000
>From Fergus Henderson on 03/11/2000 08:45:04
> > +:- typeclass enum(T) where [
> > + func to_int(T) = int,
> > + func from_int(int) = T
> > +].
>
> The documentation and interface here suggests that only types which
> are isomorphic to `int' are allowed, and that `from_int' can't fail.
> But I think the intent is that this typeclass should be allowed
> for types which are isomorphic to a subrange of `int'.
> The `from_int' function should be semidet, and you should
> document when it should fail.
I'd rather keep from_int/1 det and see an extra predicate or two added:
pred int_is_enum_image(int::in) is semidet,
pred convert_int(int::in, T::out) is semidet
Quite often (e.g. when converting between chars and ints) you know
that a conversion operation is going to succeed, so making semidet
the default mode would needlessly complicate such code.
> > +:- module sparse_bitset.
> ...
> > + % `set__equal(SetA, SetB' is true iff `SetA' and `SetB'
> > + % contain the same elements.
> > +:- pred equal(sparse_bitset(T), sparse_bitset(T)).
> > +:- mode equal(in, in) is semidet.
>
> s/set__//
s/, SetB'/, SetB)'/
> > + % `fold(Func, Set, Start)' calls Func with each element
> > + % of `Set' and an accumulator (with the initial value of
> > + % `Start'), and returns the final value.
> > + % Takes O(NlogN) time.
> > +:- func fold(func(T, U) = U, sparse_bitset(T), U) = U <= enum(T).
>
> You should document the order in which elements are processed.
I recently posted a draft spec. for collection types of which this
is obviously an instance. It'd be nice if the interface to this
module conformed.
> It may be worth defining a generic `foldr' that traverses the elements
> in reverse order, and using that.
Seconded (see above comment).
One final remark: you include pred versions of the funcs - why?!
--
Ralph Becket | MSR Cambridge | rbeck at microsoft.com
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list