[m-users.] Typeclasses

Tomas By tomas at basun.net
Sun Oct 15 00:19:54 AEDT 2017

On 2017-10-14 14:44, Mark Brown wrote:
> On Sat, Oct 14, 2017 at 11:00 PM, Dirk Ziegemeyer <dirk at ziegemeyer.de> 
> wrote:
>> Is it possible at all to define a typeclass key_value_store with the 
>> method search_value and then to declare map as an instance of this 
>> typeclass?
> No, "map" is a constructor, not a type, so you would need a
> constructor class not a typeclass.

Isn't it both?

This is the closest I can get to Dirk's example:

:- type store ---> store(map(int,int)).

:- typeclass key_value_store(S) where [
   pred search_value(S::in,int::in,int::out) is semidet

:- instance key_value_store(store) where [
   pred(search_value/3) is my_map_search

:- pred my_map_search(store::in,int::in,int::out) is semidet.
my_map_search(store(Map),K,V) :- map.search(Map,K,V).

In some of my old code I am using type classes with type variables, but 
am not really sure why it does not seem to work here.


More information about the users mailing list