[m-users.] My experiences with inst declarations and making them more user-friendly

Dirk Ziegemeyer dirk at ziegemeyer.de
Thu Mar 14 21:58:29 AEDT 2019


Hi,

from time to time I try to take advantage of Mercury’s insts to allow for more static error checking. Usually these tries end very fast because of these reasons:
1. The standard library predicates (e.g. list, map, foldl) don’t preserve subtype-insts. I have to write mode-polymorphic version of these predicates to go on. These mode-polymorphic predicate declarations are much longer and therefore harder to understand. (http://lists.mercurylang.org/archives/users/2015-March/007866.html)
2. User-defined predicate declarations become much longer, because I have to declare not only the type, but also subtype-insts.
3. With mode-polymorphic versions of predicates, the error messages might become very long and hard to read.

I’m wondering if it might be possible to make insts more user-friendly.

Maybe syntactic sugar for insts could make predicate declarations shorter. For example:
Allow inst non_empty_list to be defined on type-level instead of inst-level. The compiler should notice that type non_empty_list is nothing else than type list which has an attached inst non_empty_list.

Do you think this kind of syntactic sugar would be - at least theoretically - possible?

Dirk




More information about the users mailing list