:- module bug. :- interface. :- implementation. :- import_module int, bag. :- typeclass fooable(T) where [ func foo(T) = int ]. :- instance fooable(bag(V)) where [ foo(Bag) = bag.count(Bag) ].