[mercury-users] typeclass constraints on types
Michael Hendricks
michael at ndrix.org
Thu May 31 08:27:35 AEST 2012
Imagine a Bloom filter module with this interface:
:- type filter(T).
:- func init = filter(T).
:- func from_list(list(T)) = filter(T) <= hashable(T).
:- func insert(T, filter(T)) = filter(T) <= hashable(T).
:- pred member(T::in, filter(T)::in) is semidet <= hashable(T).
Each function and predicate declares the hashable(T) constraint. Is there
a way to factor out that constraint so that it's declared once on the type?
I found nothing in the documentation. I tried several variants with
existential types, but had no success. I'd love this to work:
:- type filter(T) <= hashable(T).
:- func init = filter(T).
:- func from_list(list(T)) = filter(T).
:- func insert(T, filter(T)) = filter(T).
:- pred member(T::in, filter(T)::in) is semidet.
Is there a way to do this with existential types?
--
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20120530/fa9b4f94/attachment.html>
More information about the users
mailing list