[m-users.] Typeclasses

Dirk Ziegemeyer dirk at ziegemeyer.de
Sat Oct 14 03:46:52 AEDT 2017


Hi,

I’m struggling to define a typeclass for key-value-stores that provides a search_value predicate.

What is wrong with to following definition?


:- import_module map.

:- typeclass key_value_store(Store) where [
    pred search_value(Store::in, K::in, V::out) is semidet
].

:- instance key_value_store(map(K, V)) where [
    pred(search_value/3) is map.search
].


The compiler throws this error message:

typeclass_test.m:029: In clause for type class method implementation:
typeclass_test.m:029:   in argument 2 of predicate `map.search'/3:
typeclass_test.m:029:   type error: variable `HeadVar__2' has type `(some [K]
typeclass_test.m:029:   K)',
typeclass_test.m:029:   expected type was `(some [K] K)'.
typeclass_test.m:029: In clause for type class method implementation:
typeclass_test.m:029:   in argument 3 of predicate `map.search'/3:
typeclass_test.m:029:   type error: variable `HeadVar__3' has type `(some [V]
typeclass_test.m:029:   V)',
typeclass_test.m:029:   expected type was `(some [V] V)’.


Thank you in advance.

Dirk


More information about the users mailing list