# Experimental library for type-class-like polymorphic predicates

**URL:** <https://swi-prolog.discourse.group/t/experimental-library-for-type-class-like-polymorphic-predicates/2072>\
**Category:** Announce\
**Created:** [March 26, 2020, 3:47pm UTC](https://swi-prolog.discourse.group/t/experimental-library-for-type-class-like-polymorphic-predicates/2072 "2020-03-26T15:47:40Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![AmbientTea](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ambienttea/32/954_2.png) [@AmbientTea](https://swi-prolog.discourse.group/u/AmbientTea)\
**Post date:** [March 26, 2020, 3:47pm UTC](https://swi-prolog.discourse.group/t/experimental-library-for-type-class-like-polymorphic-predicates/2072/1 "2020-03-26T15:47:40Z")

</div>

Hello, this is my first post here and I wanted to share a small project I’ve been tinkering with for some time and now thanks to the quarantine had some more time to work on.

I work with functional Scala at my job and I was curious to see how some basic type classes would translate to Prolog. What i came up with is that my predicates can take an additional term that describes the structure of values i pass to them, effectively exchanging composition of predicates to composition of type declarations when complex data is processed, like this:

```prolog
% list of lists of integers with addition
?- reduce(list / list(int(+)), [[1,2],[3]], Result).
Result = 6

```

Some more examples are available in the repo:

> **[AmbientTea/prolog-explicit](https://github.com/AmbientTea/prolog-explicit)**
>
> Declaratively typed polymorphic predicate library. Contribute to AmbientTea/prolog-explicit development by creating an account on GitHub.

I’m not sure how useful this sort of approach can be but I think I am going to develop it further and try to use it in something small. Any feedback or comments appreciated.

---

_[View the full topic](https://swi-prolog.discourse.group/t/experimental-library-for-type-class-like-polymorphic-predicates/2072)._
